Skip to content

Commit

Permalink
#868 readline: display 'terminal too small error' in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorg committed Sep 18, 2024
1 parent 1ea3f25 commit 5f826a3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const Name = "murex"
const (
Major = 6
Minor = 3
Revision = 4219
Revision = 4221
Branch = "develop"
BuildDate = "2024-09-18 17:08:29"
BuildDate = "2024-09-18 21:37:02"
)

// Copyright is the copyright owner string
Expand Down
2 changes: 2 additions & 0 deletions builtins/docs/summaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func init() {
"changelog/v6.0": "Despite this being a new major version release, it is a vary minor update. Aside from a handful of bugfixes, the most significant change is notice of deprecation for `=`, `let`, and `?`.",
"changelog/v6.1": "This release sees a massive jump in event-driven capabilities as well as several new features and bug fixes.",
"changelog/v6.2": "Bug fix release",
"changelog/v6.3": "This is a massive release ahead of the v7.0. This brings notifications of new deprecations, new builtins, new flags, improved CI/CD flow, and changes to the website. Unfortunately it also carries 3 breaking changes.",
}

Synonym = map[string]string{
Expand Down Expand Up @@ -1070,5 +1071,6 @@ func init() {
"changelog/v6.0": "changelog/v6.0",
"changelog/v6.1": "changelog/v6.1",
"changelog/v6.2": "changelog/v6.2",
"changelog/v6.3": "changelog/v6.3",
}
}
26 changes: 24 additions & 2 deletions utils/readline/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func (rl *Instance) getPreviewXY() (*PreviewSizeT, error) {
width = 80
}

rl.previewAutocompleteHeight(height)

preview, forward := getPreviewWidth(width)
size := &PreviewSizeT{
Height: height - rl.MaxTabCompleterRows - 10, // hintText, multi-line prompts, etc
Expand All @@ -117,6 +119,24 @@ func (rl *Instance) getPreviewXY() (*PreviewSizeT, error) {
return size, nil
}

func (rl *Instance) previewAutocompleteHeight(height int) {
switch {
case height < 40:
rl.MaxTabCompleterRows = noLargerThan(rl.MaxTabCompleterRows, 4)
case height < 30:
rl.MaxTabCompleterRows = noLargerThan(rl.MaxTabCompleterRows, 3)
case height < 20:
rl.MaxTabCompleterRows = noLargerThan(rl.MaxTabCompleterRows, 2)
}
}

func noLargerThan(src, max int) int {
if src > max {
return max
}
return src
}

func (rl *Instance) writePreviewStr() string {
if rl.previewMode == previewModeClosed {
rl.previewCache = nil
Expand Down Expand Up @@ -144,9 +164,9 @@ func (rl *Instance) writePreviewStr() string {
}

size, err := rl.getPreviewXY()
if err != nil || size.Height < 8 || size.Width < 10 {
if err != nil || size.Height < 4 || size.Width < 10 {
rl.previewCache = nil
return ""
return previewTerminalTooSmall
}

item := rl.previewItem
Expand All @@ -158,6 +178,8 @@ func (rl *Instance) writePreviewStr() string {
return ""
}

var previewTerminalTooSmall = fmt.Sprintf("%s%sTerminal too small to display preview%s", curPosSave, curHome, curPosRestore)

const (
curHome = "\x1b[H"
curPosSave = "\x1b[s"
Expand Down
3 changes: 2 additions & 1 deletion utils/readline/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ func (rl *Instance) autocompleteHeightAdjust() {
height = 25
}

rl.previewAutocompleteHeight(height)

switch {
case height <= 4:
rl.MaxTabCompleterRows = 1
case height-4 <= rl.MaxTabCompleterRows:
rl.MaxTabCompleterRows = height - 4
}

}

func (rl *Instance) moveTabCompletionHighlight(x, y int) {
Expand Down
2 changes: 1 addition & 1 deletion version.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5f826a3

Please sign in to comment.