Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,14 @@ If you want to enable this option by default, set `QuitSmall` to `true` in the c
QuitSmall: true
```

With `--wrap=none`, `QuitSmall` only checks whether the content fits vertically. When the current screen is written on exit (`IsWriteOriginal: false`, the default), lines wider than the screen are truncated. If you want `ov` to stay open whenever no-wrap content extends beyond the screen width, set `QuitSmallNoTruncate` to `true`.

```yaml
QuitSmallNoTruncate: true
```

`QuitSmallNoTruncate` has no effect when `IsWriteOriginal: true`, because the original lines are written in full regardless of the screen width.

### 4.28. <a name='suspend'></a>Suspend

You can suspend ov with `Ctrl+z`(default key).
Expand Down
1 change: 1 addition & 0 deletions ov-less.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copy it to `$XDG_CONFIG_HOME/ov/config.yaml` or start it with `ov --config ov.yaml`.
#
# QuitSmall: false # Quit if the file size is smaller than the terminal size.
# QuitSmallNoTruncate: false # Do not quit if no-wrap lines are wider than the screen.
# IsWriteOriginal: false # Write the original content when exiting.
# BeforeWriteOriginal: 0 # Extra lines above the current view to output on exit.
# AfterWriteOriginal: 0 # Extra lines below the current view to output on exit.
Expand Down
1 change: 1 addition & 0 deletions ov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copy it to `$XDG_CONFIG_HOME/ov/config.yaml` or start it with `ov --config ov.yaml`.
#
# QuitSmall: false # Quit if the file size is smaller than the terminal size.
# QuitSmallNoTruncate: false # Do not quit if no-wrap lines are wider than the screen.
# IsWriteOriginal: false # Write the original content when exiting.
# BeforeWriteOriginal: 0 # Extra lines above the current view to output on exit.
# AfterWriteOriginal: 0 # Extra lines below the current view to output on exit.
Expand Down
1 change: 1 addition & 0 deletions ov.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copy it to `$XDG_CONFIG_HOME/ov/config.yaml` or start it with `ov --config ov.yaml`.
#
# QuitSmall: false # Quit if the file size is smaller than the terminal size.
# QuitSmallNoTruncate: false # Do not quit if no-wrap lines are wider than the screen.
# IsWriteOriginal: false # Write the original content when exiting.
# BeforeWriteOriginal: 0 # Extra lines above the current view to output on exit.
# AfterWriteOriginal: 0 # Extra lines below the current view to output on exit.
Expand Down
3 changes: 3 additions & 0 deletions oviewer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type Config struct {
QuitSmall bool
// QuitSmallFilter indicates whether to quit if the output fits on one screen and a filter is applied.
QuitSmallFilter bool
// QuitSmallNoTruncate indicates whether to stay open when no-wrap lines are
// wider than the screen, instead of quitting with truncated output.
QuitSmallNoTruncate bool
// CaseSensitive is case-sensitive if true.
CaseSensitive bool
// SmartCaseSensitive indicates whether lowercase search should ignore case.
Expand Down
16 changes: 16 additions & 0 deletions oviewer/oviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,29 @@ func (root *Root) docSmall() bool {
if (end - start) >= bodyHeight {
return false
}
if root.Config.QuitSmallNoTruncate && !root.Config.IsWriteOriginal && root.hasTruncatedLine() {
return false
}

strs := tcellansi.ScreenContentToStrings(root.Screen, 0, root.scr.vWidth, start, end)
strs = tcellansi.TrimRightSpaces(strs)
root.OnExit = strs
return true
}

// hasTruncatedLine reports whether no-wrap output exceeds the available line width.
func (root *Root) hasTruncatedLine() bool {
if root.Doc.WrapMode {
return false
}
for _, lineC := range root.scr.lines {
if lineC.valid && len(lineC.lc) > root.Doc.bodyWidth {
return true
}
}
return false
}

// OutputOnExit outputs to the terminal when exiting.
func (root *Root) OutputOnExit() {
output := os.Stdout
Expand Down
49 changes: 49 additions & 0 deletions oviewer/oviewer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"io"
"os"
"path/filepath"
"reflect"
"testing"
Expand Down Expand Up @@ -536,6 +537,54 @@ func TestRoot_docSmall(t *testing.T) {
}
}

func TestRoot_docSmallNoTruncate(t *testing.T) {
tcellNewScreen = fakeScreen
defer func() {
tcellNewScreen = tcell.NewScreen
}()

fileName := filepath.Join(t.TempDir(), "long-line.txt")
if err := os.WriteFile(fileName, bytes.Repeat([]byte("x"), 81), 0o600); err != nil {
t.Fatal(err)
}

tests := []struct {
name string
noTruncate bool
isWriteOriginal bool
want bool
}{
{
name: "allow truncation",
noTruncate: false,
want: true,
},
{
name: "prevent truncation",
noTruncate: true,
want: false,
},
{
name: "original output is never truncated",
noTruncate: true,
isWriteOriginal: true,
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
root := rootFileReadHelper(t, fileName)
root.Doc.WrapMode = false
root.Config.QuitSmallNoTruncate = tt.noTruncate
root.Config.IsWriteOriginal = tt.isWriteOriginal

if got := root.docSmall(); got != tt.want {
t.Errorf("Root.docSmall() = %v, want %v", got, tt.want)
}
})
}
}

func TestRoot_setCaption(t *testing.T) {
type fields struct {
caption string
Expand Down