mirror of
https://github.com/walles/moar.git
synced 2024-11-27 01:05:23 +03:00
Enabling toggling status bar on / off
Only from within the pager right now, toggle key is `=`. Relates to #93.
This commit is contained in:
parent
0ec6e58b23
commit
0942ce5c6c
@ -62,7 +62,9 @@ type Pager struct {
|
||||
// NewPager shows lines by default, this field can hide them
|
||||
ShowLineNumbers bool
|
||||
|
||||
StatusBarStyle StatusBarStyle
|
||||
StatusBarStyle StatusBarStyle
|
||||
ShowStatusBar bool
|
||||
|
||||
UnprintableStyle UnprintableStyle
|
||||
|
||||
WrapLongLines bool
|
||||
@ -87,6 +89,7 @@ Miscellaneous
|
||||
-------------
|
||||
* Press 'q' or ESC to quit
|
||||
* Press 'w' to toggle wrapping of long lines
|
||||
* Press '=' to toggle showing the status bar at the bottom
|
||||
|
||||
Moving around
|
||||
-------------
|
||||
@ -138,6 +141,7 @@ func NewPager(r *Reader) *Pager {
|
||||
reader: r,
|
||||
quit: false,
|
||||
ShowLineNumbers: true,
|
||||
ShowStatusBar: true,
|
||||
DeInit: true,
|
||||
scrollPosition: newScrollPosition(name),
|
||||
}
|
||||
@ -284,6 +288,9 @@ func (p *Pager) onRune(char rune) {
|
||||
p.isShowingHelp = true
|
||||
}
|
||||
|
||||
case '=':
|
||||
p.ShowStatusBar = !p.ShowStatusBar
|
||||
|
||||
case 'k', 'y':
|
||||
// Clipping is done in _Redraw()
|
||||
p.scrollPosition = p.scrollPosition.PreviousLine(1)
|
||||
|
@ -58,7 +58,10 @@ func (p *Pager) redraw(spinner string) {
|
||||
if p.isShowingHelp {
|
||||
helpText = "Press ESC / q to exit help, '/' to search"
|
||||
}
|
||||
p.setFooter(statusText + spinner + " " + helpText)
|
||||
|
||||
if p.ShowStatusBar {
|
||||
p.setFooter(statusText + spinner + " " + helpText)
|
||||
}
|
||||
|
||||
default:
|
||||
panic(fmt.Sprint("Unsupported pager mode: ", p.mode))
|
||||
@ -98,6 +101,9 @@ func (p *Pager) renderScreenLines() (lines [][]twin.Cell, statusText string) {
|
||||
func (p *Pager) renderLines() ([]renderedLine, string) {
|
||||
_, height := p.screen.Size()
|
||||
wantedLineCount := height - 1
|
||||
if !p.ShowStatusBar {
|
||||
wantedLineCount = height
|
||||
}
|
||||
|
||||
inputLines := p.reader.GetLines(p.lineNumberOneBased(), wantedLineCount)
|
||||
if inputLines.lines == nil {
|
||||
|
@ -35,6 +35,7 @@ type scrollPositionCanonical struct {
|
||||
width int // From pager
|
||||
height int // From pager
|
||||
showLineNumbers bool // From pager
|
||||
showStatusBar bool // From pager
|
||||
wrapLongLines bool // From pager
|
||||
|
||||
lineNumberOneBased int // From scrollPositionInternal
|
||||
@ -47,6 +48,7 @@ func canonicalFromPager(pager *Pager) scrollPositionCanonical {
|
||||
width: width,
|
||||
height: height,
|
||||
showLineNumbers: pager.ShowLineNumbers,
|
||||
showStatusBar: pager.ShowStatusBar,
|
||||
wrapLongLines: pager.WrapLongLines,
|
||||
|
||||
lineNumberOneBased: pager.scrollPosition.internalDontTouch.lineNumberOneBased,
|
||||
@ -143,7 +145,10 @@ func (si *scrollPositionInternal) handlePositiveDeltaScreenLines(pager *Pager) {
|
||||
// This method assumes si contains a canonical position
|
||||
func (si *scrollPositionInternal) emptyBottomLinesCount(pager *Pager) int {
|
||||
_, height := pager.screen.Size()
|
||||
unclaimedViewportLines := height - 1 // Status line takes up one row
|
||||
unclaimedViewportLines := height - 1
|
||||
if !pager.ShowStatusBar {
|
||||
unclaimedViewportLines = height
|
||||
}
|
||||
|
||||
// Start counting where the current input line begins
|
||||
unclaimedViewportLines += si.deltaScreenLines
|
||||
|
Loading…
Reference in New Issue
Block a user