Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
P
pager-rs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cyril Plisko
pager-rs
Commits
929ef9cd
Commit
929ef9cd
authored
Aug 07, 2016
by
Cyril Plisko
🤔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `more` as a fallback pager
parent
4ef258bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
src/helper.rs
src/helper.rs
+10
-2
src/lib.rs
src/lib.rs
+7
-2
No files found.
src/helper.rs
View file @
929ef9cd
...
...
@@ -42,7 +42,7 @@ pub fn pipe() -> (i32, i32) {
(
fds
[
0
],
fds
[
1
])
}
pub
fn
found_in_path
(
exec
:
&
str
)
->
bool
{
fn
found_in_path
(
exec
:
&
str
)
->
bool
{
if
let
Some
(
path
)
=
env
::
var_os
(
"PATH"
)
{
let
paths
=
env
::
split_paths
(
&
path
);
for
path
in
paths
{
...
...
@@ -54,9 +54,17 @@ pub fn found_in_path(exec: &str) -> bool {
false
}
pub
fn
default_pager
()
->
Option
<
CString
>
{
if
found_in_path
(
"more"
)
{
CString
::
new
(
"more"
)
.ok
()
}
else
{
None
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
super
::
found_in_path
;
#[test]
fn
ls_found_in_path
()
{
...
...
src/lib.rs
View file @
929ef9cd
...
...
@@ -35,11 +35,12 @@
extern
crate
libc
;
use
std
::
ffi
::
CString
;
use
std
::
ptr
;
mod
helper
;
use
helper
::{
getenv
,
fork
,
close
,
dup2
,
execvp
,
pipe
};
use
helper
::{
getenv
,
fork
,
close
,
dup2
,
execvp
,
pipe
,
default_pager
};
const
DEFAULT_PAGER_ENV
:
&
'static
str
=
"PAGER"
;
...
...
@@ -69,7 +70,7 @@ impl Pager {
}
pub
fn
setup
(
&
mut
self
)
{
if
let
Some
(
pager
)
=
getenv
(
&
self
.env
)
{
if
let
Some
(
pager
)
=
self
.get_pager
(
)
{
let
(
pager_stdin
,
main_stdout
)
=
pipe
();
let
pid
=
fork
();
match
pid
{
...
...
@@ -94,4 +95,8 @@ impl Pager {
}
}
}
fn
get_pager
(
&
self
)
->
Option
<
CString
>
{
getenv
(
&
self
.env
)
.or_else
(
default_pager
)
}
}
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