Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
extrautils
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nagy Tibor
extrautils
Commits
722de2c0
Commit
722de2c0
authored
Sep 18, 2017
by
Jeremy Soller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to new termion
parent
d7bc422f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
21 deletions
+18
-21
src/bin/less.rs
src/bin/less.rs
+6
-7
src/bin/mdless.rs
src/bin/mdless.rs
+5
-6
src/bin/resize.rs
src/bin/resize.rs
+3
-3
src/bin/watch.rs
src/bin/watch.rs
+4
-5
No files found.
src/bin/less.rs
View file @
722de2c0
...
...
@@ -6,10 +6,11 @@ extern crate termion;
use
std
::
env
::
args
;
use
std
::
fs
::
File
;
use
std
::
io
::{
self
,
Write
,
Read
,
StdoutLock
};
use
std
::
io
::{
self
,
Write
,
Read
};
use
std
::
path
::
Path
;
use
extra
::
option
::
OptionalExt
;
use
termion
::
raw
::
IntoRawMode
;
static
LONG_HELP
:
&
'static
str
=
/* @MANSTART{less} */
r#"
NAME
...
...
@@ -51,8 +52,6 @@ COPYRIGHT
fn
main
()
{
let
mut
args
=
args
()
.skip
(
1
)
.peekable
();
let
stdout
=
io
::
stdout
();
let
mut
stdout
=
stdout
.lock
();
let
stdin
=
io
::
stdin
();
let
mut
stdin
=
stdin
.lock
();
let
mut
stderr
=
io
::
stderr
();
...
...
@@ -60,21 +59,21 @@ fn main() {
if
let
Some
(
x
)
=
args
.peek
()
{
if
x
==
"--help"
||
x
==
"-h"
{
// Print help.
stdout
.write
(
LONG_HELP
.as_bytes
())
.try
(
&
mut
stderr
);
io
::
stdout
()
.write
(
LONG_HELP
.as_bytes
())
.try
(
&
mut
stderr
);
return
;
}
}
else
{
let
mut
terminal
=
termion
::
get_tty
()
.try
(
&
mut
stderr
);
run
(
"-"
,
&
mut
stdin
,
&
mut
terminal
,
&
mut
stdout
)
.try
(
&
mut
stderr
);
run
(
"-"
,
&
mut
stdin
,
&
mut
terminal
,
io
::
stdout
()
)
.try
(
&
mut
stderr
);
};
while
let
Some
(
filename
)
=
args
.next
()
{
let
mut
file
=
File
::
open
(
Path
::
new
(
filename
.as_str
()))
.try
(
&
mut
stderr
);
run
(
filename
.as_str
(),
&
mut
file
,
&
mut
stdin
,
&
mut
stdout
)
.try
(
&
mut
stderr
);
run
(
filename
.as_str
(),
&
mut
file
,
&
mut
stdin
,
io
::
stdout
()
)
.try
(
&
mut
stderr
);
}
}
fn
run
(
path
:
&
str
,
file
:
&
mut
Read
,
controls
:
&
mut
Read
,
stdout
:
&
mut
StdoutLock
)
->
std
::
io
::
Result
<
()
>
{
fn
run
<
W
:
IntoRawMode
>
(
path
:
&
str
,
file
:
&
mut
Read
,
controls
:
&
mut
Read
,
stdout
:
W
)
->
std
::
io
::
Result
<
()
>
{
let
mut
string
=
String
::
new
();
file
.read_to_string
(
&
mut
string
)
?
;
...
...
src/bin/mdless.rs
View file @
722de2c0
...
...
@@ -7,7 +7,7 @@ extern crate termion;
use
std
::
env
::
args
;
use
std
::
fs
::
File
;
use
std
::
io
::{
self
,
Write
,
Read
,
StdoutLock
};
use
std
::
io
::{
self
,
Write
,
Read
};
use
std
::
path
::{
Path
,
PathBuf
};
use
std
::
str
::
Chars
;
...
...
@@ -69,8 +69,7 @@ fn terminal_path() -> String {
fn
main
()
{
let
mut
args
=
args
()
.skip
(
1
)
.peekable
();
let
stdout
=
io
::
stdout
();
let
mut
stdout
=
stdout
.lock
();
let
mut
stdout
=
io
::
stdout
();
let
stdin
=
io
::
stdin
();
let
mut
stdin
=
stdin
.lock
();
let
mut
stderr
=
io
::
stderr
();
...
...
@@ -189,7 +188,7 @@ impl Block {
blocks
}
fn
draw
(
&
self
,
to
:
&
mut
RawTerminal
<&
mut
StdoutLock
>
,
path
:
&
PathBuf
,
next
:
&
mut
Vec
<
PathBuf
>
,
next_i
:
usize
)
->
std
::
io
::
Result
<
usize
>
{
fn
draw
<
W
:
IntoRawMode
>
(
&
self
,
to
:
&
mut
RawTerminal
<
W
>
,
path
:
&
PathBuf
,
next
:
&
mut
Vec
<
PathBuf
>
,
next_i
:
usize
)
->
std
::
io
::
Result
<
usize
>
{
let
mut
count
=
0
;
match
*
self
{
...
...
@@ -290,7 +289,7 @@ impl Buffer {
Ok
(
res
)
}
fn
draw
(
&
self
,
to
:
&
mut
RawTerminal
<&
mut
StdoutLock
>
,
path
:
&
PathBuf
,
next
:
&
mut
Vec
<
PathBuf
>
,
next_i
:
usize
,
w
:
u16
,
h
:
u16
)
->
std
::
io
::
Result
<
usize
>
{
fn
draw
<
W
:
IntoRawMode
>
(
&
self
,
to
:
&
mut
RawTerminal
<
W
>
,
path
:
&
PathBuf
,
next
:
&
mut
Vec
<
PathBuf
>
,
next_i
:
usize
,
w
:
u16
,
h
:
u16
)
->
std
::
io
::
Result
<
usize
>
{
write!
(
to
,
"{}{}{}"
,
clear
::
All
,
style
::
Reset
,
cursor
::
Goto
(
1
,
1
))
?
;
let
mut
y
=
0
;
...
...
@@ -336,7 +335,7 @@ impl Buffer {
}
}
fn
run
(
mut
path
:
PathBuf
,
file
:
&
mut
Read
,
controls
:
&
mut
Read
,
stdout
:
&
mut
StdoutLock
)
->
std
::
io
::
Result
<
()
>
{
fn
run
<
W
:
IntoRawMode
>
(
mut
path
:
PathBuf
,
file
:
&
mut
Read
,
controls
:
&
mut
Read
,
stdout
:
&
mut
W
)
->
std
::
io
::
Result
<
()
>
{
let
mut
stdout
=
stdout
.into_raw_mode
()
?
;
let
(
w
,
h
)
=
{
...
...
src/bin/resize.rs
View file @
722de2c0
...
...
@@ -9,8 +9,8 @@ use termion::raw::IntoRawMode;
fn
main
()
{
let
mut
stderr
=
io
::
stderr
();
let
mut
terminal
=
termion
::
get_tty
()
.try
(
&
mut
stderr
)
.into_raw_mode
()
.try
(
&
mut
stderr
);
let
mut
terminal
=
termion
::
get_tty
()
.try
(
&
mut
stderr
)
;
let
mut
terminal
=
terminal
.into_raw_mode
()
.try
(
&
mut
stderr
);
write!
(
terminal
,
"{}"
,
cursor
::
Save
)
.unwrap
();
terminal
.flush
()
.unwrap
();
...
...
@@ -22,7 +22,7 @@ fn main() {
write!
(
terminal
,
"{}"
,
cursor
::
Restore
)
.unwrap
();
terminal
.flush
()
.unwrap
();
drop
(
terminal
);
println!
(
"export COLUMNS={};"
,
w
);
...
...
src/bin/watch.rs
View file @
722de2c0
...
...
@@ -7,7 +7,7 @@ extern crate termion;
use
std
::{
cmp
,
str
,
thread
};
use
std
::
env
::
args
;
use
std
::
io
::{
self
,
Write
,
Read
,
StdoutLock
};
use
std
::
io
::{
self
,
Write
,
Read
};
use
std
::
process
::{
self
,
Command
,
Stdio
};
use
std
::
time
::
Duration
;
...
...
@@ -57,8 +57,7 @@ COPYRIGHT
fn
main
()
{
let
mut
args
=
args
()
.skip
(
1
);
let
stdout
=
io
::
stdout
();
let
mut
stdout
=
stdout
.lock
();
let
mut
stdout
=
io
::
stdout
();
let
mut
stderr
=
io
::
stderr
();
let
mut
command
=
String
::
new
();
...
...
@@ -98,10 +97,10 @@ fn main() {
process
::
exit
(
1
);
}
run
(
command
,
interval
,
&
mut
stdout
)
.try
(
&
mut
stderr
);
run
(
command
,
interval
,
stdout
)
.try
(
&
mut
stderr
);
}
fn
run
(
command
:
String
,
interval
:
u64
,
stdout
:
&
mut
StdoutLock
)
->
std
::
io
::
Result
<
()
>
{
fn
run
<
W
:
IntoRawMode
>
(
command
:
String
,
interval
:
u64
,
mut
stdout
:
W
)
->
std
::
io
::
Result
<
()
>
{
let
title
=
format!
(
"Every {}s: {}"
,
interval
,
command
);
let
mut
stdout
=
stdout
.into_raw_mode
()
?
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment