-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpager.elv
62 lines (53 loc) · 1.99 KB
/
pager.elv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (c) 2016, 2020, Cody Opel <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use github.com/chlorm/elvish-stl/env
use github.com/chlorm/elvish-stl/path
use github.com/chlorm/elvish-stl/platform
use github.com/chlorm/elvish-stl/utils
fn get {
var pagers = [
'less'
'most'
'more'
]
var pager = (utils:get-preferred-cmd 'PREFERRED_PAGERS' $pagers)
put $pager
}
fn set {|&static=$nil|
var pager = $static
if (eq $static $nil) {
set pager = (get)
}
if $platform:is-windows {
set pager = (path:escape-unixlike (path:unescape $pager))
}
env:set 'PAGER' $pager
env:set 'MANPAGER' $pager
if (==s (path:basename $pager) 'less') {
env:set 'LESS' '--RAW-CONTROL-CHARS'
env:set 'LESSCHARSET' 'utf-8'
env:unset 'LESS_IS_MORE'
env:set 'LESS_TERMCAP_mb' (e:tput 'blink'; e:tput 'setaf' 3)
env:set 'LESS_TERMCAP_md' (e:tput 'bold'; e:tput 'setaf' 6)
env:set 'LESS_TERMCAP_me' (e:tput 'sgr0')
env:set 'LESS_TERMCAP_so' (e:tput 'smso'; e:tput 'setaf' 8; e:tput 'setab' 3)
env:set 'LESS_TERMCAP_se' (e:tput 'sgr0'; e:tput 'rmso')
env:set 'LESS_TERMCAP_us' (e:tput 'smul'; e:tput 'setaf' 3)
env:set 'LESS_TERMCAP_ue' (e:tput 'sgr0'; e:tput 'rmul')
env:set 'LESS_TERMCAP_mr' (e:tput 'rev')
env:set 'LESS_TERMCAP_mh' (e:tput 'dim')
# some terminals don't understand SGR escape sequences
env:set 'GROFF_NO_SGR' 1
}
}