1
1
mirror of https://github.com/walles/moar.git synced 2024-07-07 08:36:29 +03:00

Reboot in Go

This commit is contained in:
Johan Walles 2019-06-08 22:12:52 +02:00
commit f3097e7450
16 changed files with 290628 additions and 0 deletions

8
.whitesource Normal file
View File

@ -0,0 +1,8 @@
{
"generalSettings": {
"shouldScanRepo": true
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure"
}
}

26
LICENSE Normal file
View File

@ -0,0 +1,26 @@
Copyright (c) 2013, johan.walles@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

340
README.md Normal file
View File

@ -0,0 +1,340 @@
Moar is a pager. It's designed to just do the right thing without any
configuration:
![Moar displaying its own test suite](http://walles.github.io/moar/images/moar.png)
The intention is that Moar should work as a drop-in replacement for
[Less](http://www.greenwoodsoftware.com/less/). If you find that Moar
doesn't work that way,
[please report it](https://github.com/walles/moar/issues)!
Doing the right thing includes:
* **Syntax highlight** source code by default if
[GNU Source-highlight](http://www.gnu.org/software/src-highlite/)
is installed.
* **Search is incremental** / find-as-you-type just like in
[Chrome](http://www.google.com/chrome) or
[Emacs](http://www.gnu.org/software/emacs/)
* Search becomes case sensitive if you add any UPPER CASE characters
to your search terms, just like in Emacs
* [Regexp](http://en.wikipedia.org/wiki/Regular_expression#Basic_concepts)
search if your search string is a valid regexp
* Supports displaying ANSI color coded texts (like the output from
"git diff" for example)
* Supports UTF-8 input and output
* The position in the file is always shown
Installing
----------
FIXME: Go install instructions
...
And now you can just invoke `moar` from the prompt!
Setting Moar as Your Default Pager
----------------------------------
Set it as your default pager by adding...
```bash
export PAGER=/usr/local/bin/moar
```
... to your `.bashrc`.
Issues
------
Issues are tracked [here](https://github.com/walles/moar/issues), or
you can send questions to <johan.walles@gmail.com>.
Developing
----------
FIXME: Go build instructions
FIXME: Go test instructions
Making a new Release
--------------------
FIXME: Go release instructions
TODO
----
* Make search work cross color boundaries. Currently, if you have a syntax
highlighted line and search for something across a color change you won't get
any match.
* Handle search hits to the right of the right screen edge. Searching
forwards should move first right, then to the left edge and
down. Searching backwards should move first left, then up and to the
right edge (if needed for showing search hits).
* Auto generate the in-program help text to correctly correspond to
the actual key bindings.
* If you try to bind the same key to multiple actions, that must be caught by
the unit tests.
* If you try to bind to an action that doesn't exist, that must be caught by
the unit tests.
* Read `source-highlight` output as a stream for startup performance reasons.
This must work when `source-highlight` fails as well, and when it succeeds on
an empty input file.
* When skipping to the end, either while searching or when the user presses '>',
try finding the end of the file for at most two seconds, then show wherever we
are. Pressing '>' again or searching again should make another attempt until
we're actually done.
* Redefine 'g' without any prefix to prompt for which line to go
to. This definition makes more sense to me than having to prefix 'g'
to jump.
* Start at a certain line if run as "moar.rb file.txt:42"
* Enable home / end using home / end keys.
* Always print the name of the file being shown in the status field.
* Support viewing multiple files by pushing them in reverse order on
the view stack.
* Add search line editing
* Try to find a newer Ruby version if needed for color support and
exec() with that instead if available.
* Write "/ to search" somewhere in the status field
* Incremental search using ^s and ^r like in Emacs
* Gunzip input files with .gz extension before displaying them
* Warn but don't hang if we get an incomplete UTF-8 sequence from
getch() in wide_getch(). Hanging won't be that much of a problem
assuming users will press more keys if nothing happens, thus
resolving the hang.
* Enable up / down using the mouse wheel.
DONE
----
* Enable exiting using q (restores screen)
* Handle the terminal window getting resized.
* Print info line in inverse video
* Enable up / down using arrow keys.
* Prevent pressing down past the last line of the file.
* Enable out-of-file visualization with ~ like less.
* Enable up / down using page-up and page-down keys.
* Enable home / end using < and >.
* Enable file input.
* Enable continuous position display with everything we know (lines
visible, percentages, like less).
* Enable stdin input.
* Truncate lines that are longer than the screen width
* Make sure we can print all the way into the rightmost column of the
screen when truncating too long lines. We should strip() lines
before we print them and manually move the cursor to the next line
after each.
* Handle all kinds of line endings.
* Handle files missing an ending newline.
* Handle hitting BACKSPACE in the search field
* Incremental search using /
* Typing backspace in the line editor when it's empty should make the
line editor say "done".
* Change out-of-file visualization to writing --- after the end of the
file and leaving the rest of the screen blank.
* Scroll down if we have no search hits on the current screen
* Wrap search if we have search hits above but not below
* Find next using n
* Highlight search hits using reverse video
* Make sure we can properly render all lines of /etc/php.ini.default
without the bottom-of-the-screen prompt moving around.
* Find previous using N
* Indicate when we're wrapping the search while pressing n.
* Indicate when we're wrapping the search while pressing N.
* Highlight all matches while searching
* Scroll down one line on RETURN
* Print warnings to stderr after the run, for example if we aren't
using color support because of a too-old version of Ruby.
* Make stdin input work even on newer (than 1.8) versions of
Ruby. Apparently
[this patch](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=7641&r2=7649&diff_format=h)
is the reason it doesn't
work. [Reported to the Ruby issue tracker](https://bugs.ruby-lang.org/issues/9067),
let's see how that goes.
* Enable displaying colorized output from "git diff"
* Arrow down through the whole file, then arrow up again
* Page down through the whole file, then page up again
* Search highlighting
* Use the same algorithm for highlighting as for determining which
lines match.
* Make the search case sensitive only if it contains any capital
letters.
* Do a regexp search if the search term is a valid regexp, otherwise
just use it as a substring.
* Make the search case sensitive only if it contains any capital
letters, for both regexps and non-regexps.
* If we print warnings at the end, also print an URL where they can be
reported.
* If we crash with a stacktrace, print an URL where it can be reported
* Enable sideways scrolling using arrow keys.
* Warn about any unhandled keypresses during search.
* Enable displaying a man page
* Arrow down through the whole file, then arrow up again
* Page down through the whole file, then page up again
* Search highlighting
* Make sure we get the line length right even with unicode characters
present in the lines. Verify by looking at where the truncation
markers end up.
* Make sure we can search for unicode characters
* Work around
[the issue with getch not returning unicode chars](https://bugs.ruby-lang.org/issues/9094)
* Work around
[the issue with Regexp.quote() returning non-unicode strings](https://bugs.ruby-lang.org/issues/9096)
* Warn but don't crash if we get an invalid UTF-8 sequence from
getch() in wide_getch().
* Make sure the LANG environment variable is printed if there are
warnings.
* Make sure some kind of platform information is printed if there are
warnings.
* Make sure the Ruby version is printed if there are warnings.
* Startup exceptions should be caught through the same reporting
thingy as everything else.
* We must not crash on getting binary data. Testcase: "moar.rb /bin/ls"
* Fix handling of TAB characters in the input
* Run rubocop as part of test.rb if installed and have the exit code
reflect any issues.
* Make sure version information is printed if there are warnings.
* Make it possible to install system-wide using "rake install". Don't
forget to fix the version number when doing this.
* Enable --help for help
* Enable --version for version information.
* Report command line errors, think about different command line
requirements depending on whether we're piping input into moar.rb or
listing input files on the command line.
Command line formats we want to support:
* moar.rb file.txt
* moar.rb < file.txt
Command line formats we *don't* want to support:
* moar.rb file1.txt file2.txt
* moar.rb file1.txt < file2.txt
* Enable 'h', '?' or F1 for help
* Print something nice on file-not-found.
* Test on Ubuntu
* Test on Ruby 1.8.something. We did, and due to missing UTF-8 support
in Ruby 1.8 we just dropped support for it. Now we print an error
message if Ruby < 1.9 is detected.
* Add info to the end of the --help output on how to set Moar to be
your default pager.
* Add licensing information (BSD)
* Enable source code highlighting by pre-filtering using GNU
Source-highlight.
* Retain the search string when pressing / to search a second time.
* Exit search mode and cancel the search on ESC. Because that's what I
feel like pressing.
* Exit search mode and cancel the search on ^G. For compatibility with
Emacs.
* Make sure searching for an upper case unicode character turns on
case sensitive search.
* Doing moar.rb on an arbitrary binary (like /bin/ls) should put all
line-continuation markers at the rightmost column. This really
means our truncation code must work even with things like tabs and
various control characters.
* Enable exiting using ^c (without restoring the screen).
* Enable pass-through operation unless $stdout.isatty()
* Accept numeric prefixes just like less. Implement for 'g', 'G' and
SPACE to begin with.
* Exit search on pressing up / down / pageup / pagedown keys and
scroll. I attempted to do that spontaneously, so it's probably a
good idea.
* Searching for something above us should wrap the search.
* When pressing '/' to edit the search terms, find a hit and
re-highlight.
* Make sure "git grep" output gets highlighted properly.
* Lazy load big / slow streams
* Add making binaries to the Making a new Release section above.

75
sample-files/dos.txt Normal file
View File

@ -0,0 +1,75 @@
1 #!/usr/bin/ruby
2
3 require "curses"
4
5 class Moar
6 include Curses
7
8 def initialize(file)
9 @first_line = 0
10 @file = file
11 @lines = IO.readlines(file)
12 @last_key = 0
13 end
14
15 def draw_screen()
16 # @first_line must not be closer than lines-2 from the end
17 max_first_line = @lines.size - (lines - 1)
18 @first_line = [@first_line, max_first_line].min()
19
20 # @first_line cannot be negative
21 @first_line = [0, @first_line].max()
22
23 clear()
24 setpos(0, 0)
25
26 attrset(A_NORMAL)
27 last_line = @first_line + lines - 2
28 for line_number in @first_line..last_line do
29 if line_number < @lines.size
30 addstr(@lines[line_number])
31 else
32 addstr("~\n")
33 end
34 end
35
36 attrset(A_REVERSE)
37 status = "Lines #{@first_line + 1}-"
38 status += "#{[@lines.size, last_line].min()}"
39 status += "/#{@lines.size}"
40 addstr(status)
41
42 refresh()
43 end
44
45 def run
46 init_screen
47 noecho
48 stdscr.keypad(true)
49
50 begin
51 crmode
52 while true
53 draw_screen()
54
55 key = getch()
56 case key
57 when ?q.ord
58 break
59 when Key::RESIZE
60 draw_screen()
61 when Key::DOWN
62 @first_line += 1
63 when Key::UP
64 @first_line -= 1
65 end
66
67 @last_key = key
68 end
69 ensure
70 close_screen
71 end
72 end
73 end
74
75 Moar.new(ARGV[0]).run()

View File

@ -0,0 +1,100 @@
commit 0ccc858f87d70c302117db9034186754a4091f23
Author: Johan Walles <johan.walles@gmail.com>
Date: Thu Oct 24 20:45:40 2013 +0200
Prioritize the TODO file
diff --git a/TODO.txt b/TODO.txt
index 52551e7..663ffd7 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,36 +1,48 @@
Moar is a pager. It's designed to be easy to use and just do the
right thing without any configuration.

-TODO (in some order):
+TODO (before using it myself)
+-----------------------------
+* Scroll down one line on RETURN

-* Write "/ to search" somewhere in the status field
+* Enable displaying ANSI-colored input
+
+
+TODO (before github)
+--------------------

+TODO (before trying to get others to use it)
+--------------------------------------------
* Do a regexp search if the search term is a valid regexp, otherwise
just use it as a substring.

-* Make the search case sensitive only if it contains any capital
- letters. This goes for both regexps and non-regexps.
-
* Make sure we can search for unicode characters

-* Make sure searching for an upper case unicode character turns on
- case sensitive search.
-
* Make sure we get the line length right even with unicode characters
present in the lines. Verify by looking at where the truncation
markers end up.

-* Scroll down one line on RETURN
-
* Enable sideways scrolling using arrow keys.

* Handle search hits to the right of the right screen edge

-* Interactive search using ^s and ^r like in Emacs
+* Enable 'h' or '?' for help

-* Highlight all matches while searching
+* Report command line errors, think about when to use $stdin for input
+ vs what commands we accept

-* Enable displaying ANSI-colored input
+
+TODO (bonus)
+------------
+* Make the search case sensitive only if it contains any capital
+ letters. This goes for both regexps and non-regexps.
+
+* Make sure searching for an upper case unicode character turns on
+ case sensitive search.
+
+* Write "/ to search" somewhere in the status field
+
+* Interactive search using ^s and ^r like in Emacs

* Enable filtered input, start with zcat as a filter

@@ -47,11 +59,6 @@ TODO (in some order):

* Enable up / down using the mouse wheel.

-* Enable 'h' or '?' for help
-
-* Report command line errors, think about when to use $stdin for input
- vs what commands we accept
-
* Enable pass-through operation unless $stdout.isatty()

* Doing moar.rb on an arbitrary binary (like /bin/ls) should put all
@@ -60,7 +67,8 @@ TODO (in some order):
various control characters.


-DONE:
+DONE
+----
* Enable exiting using q (restores screen)

* Handle the terminal window getting resized.
@@ -121,3 +129,5 @@ DONE:
* Indicate when we're wrapping the search while pressing n.

* Indicate when we're wrapping the search while pressing N.
+
+* Highlight all matches while searching

197
sample-files/hej.txt Normal file
View File

@ -0,0 +1,197 @@
PRINTF(1) BSD General Commands Manual PRINTF(1)
NNAAMMEE
pprriinnttff -- formatted output
SSYYNNOOPPSSIISS
pprriinnttff _f_o_r_m_a_t [_a_r_g_u_m_e_n_t_s _._._.]
DDEESSCCRRIIPPTTIIOONN
The pprriinnttff utility formats and prints its arguments, after the first,
under control of the _f_o_r_m_a_t. The _f_o_r_m_a_t is a character string which con-
tains three types of objects: plain characters, which are simply copied
to standard output, character escape sequences which are converted and
copied to the standard output, and format specifications, each of which
causes printing of the next successive _a_r_g_u_m_e_n_t.
The _a_r_g_u_m_e_n_t_s after the first are treated as strings if the corresponding
format is either cc, bb or ss; otherwise it is evaluated as a C constant,
with the following extensions:
++oo A leading plus or minus sign is allowed.
++oo If the leading character is a single or double quote, the value
is the ASCII code of the next character.
The format string is reused as often as necessary to satisfy the
_a_r_g_u_m_e_n_t_s. Any extra format specifications are evaluated with zero or
the null string.
Character escape sequences are in backslash notation as defined in the
ANSI X3.159-1989 (``ANSI C89''), with extensions. The characters and
their meanings are as follows:
\\aa Write a <bell> character.
\\bb Write a <backspace> character.
\\cc Ignore remaining characters in this string.
\\ff Write a <form-feed> character.
\\nn Write a <new-line> character.
\\rr Write a <carriage return> character.
\\tt Write a <tab> character.
\\vv Write a <vertical tab> character.
\\'' Write a <single quote> character.
\\\\ Write a backslash character.
\\_n_u_m
\\00_n_u_m Write an 8-bit character whose ASCII value is the 1-, 2-,
or 3-digit octal number _n_u_m.
Each format specification is introduced by the percent character (``%'').
The remainder of the format specification includes, in the following
order:
Zero or more of the following flags:
## A `#' character specifying that the value should be
printed in an ``alternate form''. For cc, dd, and ss, for-
mats, this option has no effect. For the oo formats the
precision of the number is increased to force the first
character of the output string to a zero. For the xx (XX)
format, a non-zero result has the string 0x (0X)
prepended to it. For ee, EE, ff, gg, and GG, formats, the
result will always contain a decimal point, even if no
digits follow the point (normally, a decimal point only
appears in the results of those formats if a digit fol-
lows the decimal point). For gg and GG formats, trailing
zeros are not removed from the result as they would oth-
erwise be;
-- A minus sign `-' which specifies _l_e_f_t _a_d_j_u_s_t_m_e_n_t of the
output in the indicated field;
++ A `+' character specifying that there should always be a
sign placed before the number when using signed formats.
` ' A space specifying that a blank should be left before a
positive number for a signed format. A `+' overrides a
space if both are used;
00 A zero `0' character indicating that zero-padding should
be used rather than blank-padding. A `-' overrides a `0'
if both are used;
Field Width:
An optional digit string specifying a _f_i_e_l_d _w_i_d_t_h; if the output
string has fewer characters than the field width it will be
blank-padded on the left (or right, if the left-adjustment indi-
cator has been given) to make up the field width (note that a
leading zero is a flag, but an embedded zero is part of a field
width);
Precision:
An optional period, `..', followed by an optional digit string
giving a _p_r_e_c_i_s_i_o_n which specifies the number of digits to appear
after the decimal point, for ee and ff formats, or the maximum num-
ber of characters to be printed from a string; if the digit
string is missing, the precision is treated as zero;
Format:
A character which indicates the type of format to use (one of
ddiioouuxxXXffFFeeEEggGGaaAAccssbb). The uppercase formats differ from their low-
ercase counterparts only in that the output of the former is
entirely in uppercase. The floating-point format specifiers
(ffFFeeEEggGGaaAA) may be prefixed by an LL to request that additional
precision be used, if available.
A field width or precision may be `**' instead of a digit string. In this
case an _a_r_g_u_m_e_n_t supplies the field width or precision.
The format characters and their meanings are:
ddiioouuXXxx The _a_r_g_u_m_e_n_t is printed as a signed decimal (d or i),
unsigned octal, unsigned decimal, or unsigned hexadecimal (X
or x), respectively.
ffFF The _a_r_g_u_m_e_n_t is printed in the style `[-]ddd.ddd' where the
number of d's after the decimal point is equal to the preci-
sion specification for the argument. If the precision is
missing, 6 digits are given; if the precision is explicitly
0, no digits and no decimal point are printed. The values
infinity and _N_a_N are printed as `inf' and `nan', respec-
tively.
eeEE The _a_r_g_u_m_e_n_t is printed in the style ee `[-_d_._d_d_d+-_d_d]' where
there is one digit before the decimal point and the number
after is equal to the precision specification for the argu-
ment; when the precision is missing, 6 digits are produced.
The values infinity and _N_a_N are printed as `inf' and `nan',
respectively.
ggGG The _a_r_g_u_m_e_n_t is printed in style ff (FF) or in style ee (EE)
whichever gives full precision in minimum space.
aaAA The _a_r_g_u_m_e_n_t is printed in style `[-_h_._h_h_h+-p_d]' where there
is one digit before the hexadecimal point and the number
after is equal to the precision specification for the argu-
ment; when the precision is missing, enough digits are pro-
duced to convey the argument's exact double-precision float-
ing-point representation. The values infinity and _N_a_N are
printed as `inf' and `nan', respectively.
cc The first character of _a_r_g_u_m_e_n_t is printed.
ss Characters from the string _a_r_g_u_m_e_n_t are printed until the end
is reached or until the number of characters indicated by the
precision specification is reached; however if the precision
is 0 or missing, all characters in the string are printed.
bb As for ss, but interpret character escapes in backslash nota-
tion in the string _a_r_g_u_m_e_n_t.
%% Print a `%'; no argument is used.
The decimal point character is defined in the program's locale (category
LC_NUMERIC).
In no case does a non-existent or small field width cause truncation of a
field; padding takes place only if the specified field width exceeds the
actual width.
EEXXIITT SSTTAATTUUSS
The pprriinnttff utility exits 0 on success, and >0 if an error occurs.
CCOOMMPPAATTIIBBIILLIITTYY
The traditional BSD behavior of converting arguments of numeric formats
not beginning with a digit to the ASCII code of the first character is
not supported.
SSEEEE AALLSSOO
echo(1), printf(3)
SSTTAANNDDAARRDDSS
The pprriinnttff command is expected to be mostly compatible with the IEEE Std
1003.2 (``POSIX.2'') specification.
HHIISSTTOORRYY
The pprriinnttff command appeared in 4.3BSD-Reno. It is modeled after the
standard library function, printf(3).
BBUUGGSS
Since the floating point numbers are translated from ASCII to floating-
point and then back again, floating-point precision may be lost. (By
default, the number is translated to an IEEE-754 double-precision value
before being printed. The LL modifier may produce additional precision,
depending on the hardware platform.)
ANSI hexadecimal character constants were deliberately not provided.
The escape sequence \000 is the string terminator. When present in the
argument for the bb format, the argument will be truncated at the \000
character.
Multibyte characters are not recognized in format strings (this is only a
problem if `%' can appear inside a multibyte character).
Parsing of - arguments is also somewhat different from printf(3), where
unknown arguments are simply printed instead of being flagged as errors.
BSD April 14, 2005 BSD

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,202 @@
Search for monkeys in this file.
monkeys
Search for monkeys in this file.
monkeys

75
sample-files/long.txt Normal file
View File

@ -0,0 +1,75 @@
1 #!/usr/bin/ruby
2
3 require "curses"
4
5 class Moar
6 include Curses
7
8 def initialize(file)
9 @first_line = 0
10 @file = file
11 @lines = IO.readlines(file)
12 @last_key = 0
13 end
14
15 def draw_screen()
16 # @first_line must not be closer than lines-2 from the end
17 max_first_line = @lines.size - (lines - 1)
18 @first_line = [@first_line, max_first_line].min()
19
20 # @first_line cannot be negative
21 @first_line = [0, @first_line].max()
22
23 clear()
24 setpos(0, 0)
25
26 attrset(A_NORMAL)
27 last_line = @first_line + lines - 2
28 for line_number in @first_line..last_line do
29 if line_number < @lines.size
30 addstr(@lines[line_number])
31 else
32 addstr("~\n")
33 end
34 end
35
36 attrset(A_REVERSE)
37 status = "Lines #{@first_line + 1}-"
38 status += "#{[@lines.size, last_line].min()}"
39 status += "/#{@lines.size}"
40 addstr(status)
41
42 refresh()
43 end
44
45 def run
46 init_screen
47 noecho
48 stdscr.keypad(true)
49
50 begin
51 crmode
52 while true
53 draw_screen()
54
55 key = getch()
56 case key
57 when ?q.ord
58 break
59 when Key::RESIZE
60 draw_screen()
61 when Key::DOWN
62 @first_line += 1
63 when Key::UP
64 @first_line -= 1
65 end
66
67 @last_key = key
68 end
69 ensure
70 close_screen
71 end
72 end
73 end
74
75 Moar.new(ARGV[0]).run()

View File

@ -0,0 +1,3 @@
This works: bboolldd
As does this: _u_n_d_e_r_l_i_n_e
This breaks: _bb_oo_ll_dd _aa_nn_dd _uu_nn_dd_ee_rr_ll_ii_nn_ee

View File

@ -0,0 +1,75 @@
1 #!/usr/bin/ruby
2
3 require "curses"
4
5 class Moar
6 include Curses
7
8 def initialize(file)
9 @first_line = 0
10 @file = file
11 @lines = IO.readlines(file)
12 @last_key = 0
13 end
14
15 def draw_screen()
16 # @first_line must not be closer than lines-2 from the end
17 max_first_line = @lines.size - (lines - 1)
18 @first_line = [@first_line, max_first_line].min()
19
20 # @first_line cannot be negative
21 @first_line = [0, @first_line].max()
22
23 clear()
24 setpos(0, 0)
25
26 attrset(A_NORMAL)
27 last_line = @first_line + lines - 2
28 for line_number in @first_line..last_line do
29 if line_number < @lines.size
30 addstr(@lines[line_number])
31 else
32 addstr("~\n")
33 end
34 end
35
36 attrset(A_REVERSE)
37 status = "Lines #{@first_line + 1}-"
38 status += "#{[@lines.size, last_line].min()}"
39 status += "/#{@lines.size}"
40 addstr(status)
41
42 refresh()
43 end
44
45 def run
46 init_screen
47 noecho
48 stdscr.keypad(true)
49
50 begin
51 crmode
52 while true
53 draw_screen()
54
55 key = getch()
56 case key
57 when ?q.ord
58 break
59 when Key::RESIZE
60 draw_screen()
61 when Key::DOWN
62 @first_line += 1
63 when Key::UP
64 @first_line -= 1
65 end
66
67 @last_key = key
68 end
69 ensure
70 close_screen
71 end
72 end
73 end
74
75 Moar.new(ARGV[0]).run()

23
sample-files/short.txt Normal file
View File

@ -0,0 +1,23 @@
1 #
2 # Default PF configuration file.
3 #
4 # This file contains the main ruleset, which gets automatically loaded
5 # at startup. PF will not be automatically enabled, however. Instead,
6 # each component which utilizes PF is responsible for enabling and disabling
7 # PF via -E and -X as documented in pfctl(8). That will ensure that PF
8 # is disabled only when the last enable reference is released.
9 #
10 # Care must be taken to ensure that the main ruleset does not get flushed,
11 # as the nested anchors rely on the anchor point defined here.
12 #
13 # See pf.conf(5) for syntax.
14 #
15
16 #
17 # com.apple anchor point
18 #
19 scrub-anchor "com.apple/*"
20 nat-anchor "com.apple/*"
21 rdr-anchor "com.apple/*"
22 anchor "com.apple/*"
23 load anchor "com.apple" from "/etc/pf.anchors/com.apple"

11
sample-files/test.log Normal file
View File

@ -0,0 +1,11 @@
Run options:
# Running tests:
...................[?1049h(B[?7h[?1h=.
Finished tests in 0.006124s, 3265.8393 tests/s, 10940.5617 assertions/s.
20 tests, 67 assertions, 0 failures, 0 errors, 0 skips
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

View File

@ -0,0 +1,2 @@
first line
second line

11
sample-files/utf8.txt Normal file
View File

@ -0,0 +1,11 @@
Här är en fil som innehåller alla bokstäverna i ordet "räksmörgås" och den här raden är jättelång.
åäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖ
åäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖ
åäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖ
åäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖ
åäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖåäöÅÄÖ

3
sample-files/with-tabs.c Normal file
View File

@ -0,0 +1,3 @@
int main(int argc, char *argv[]) {
printf("Hej\n");
}