mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "40c3cecabb38a68064727368b5882196a59d34d9" and "7d487bfc986e2ba1f7197437f75aa26737d8bca0" have entirely different histories.
40c3cecabb
...
7d487bfc98
|
@ -1,8 +1,7 @@
|
||||||
# 🎀 Changelog
|
# 🎀 Changelog
|
||||||
|
|
||||||
## [2.2.2] - 2024-04-16
|
## Unreleased
|
||||||
### Fixed
|
### Fixed
|
||||||
- Line refresh fixes (less flicker)
|
|
||||||
- Do more checks for a TTY
|
- Do more checks for a TTY
|
||||||
- Panic if ENOTTY is thrown from readline
|
- Panic if ENOTTY is thrown from readline
|
||||||
- use `x/term` function to check if a terminal
|
- use `x/term` function to check if a terminal
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module hilbish
|
module hilbish
|
||||||
|
|
||||||
go 1.18
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/arnodel/golua v0.0.0-20220221163911-dfcf252b6f86
|
github.com/arnodel/golua v0.0.0-20220221163911-dfcf252b6f86
|
||||||
|
|
|
@ -76,8 +76,6 @@ const (
|
||||||
seqCursorTopLeft = "\x1b[H" // Clears screen and places cursor on top-left
|
seqCursorTopLeft = "\x1b[H" // Clears screen and places cursor on top-left
|
||||||
|
|
||||||
seqGetCursorPos = "\x1b6n" // response: "\x1b{Line};{Column}R"
|
seqGetCursorPos = "\x1b6n" // response: "\x1b{Line};{Column}R"
|
||||||
seqHideCursor = "\x1b[?25l"
|
|
||||||
seqUnhideCursor = "\x1b[?25h"
|
|
||||||
|
|
||||||
seqCtrlLeftArrow = "\x1b[1;5D"
|
seqCtrlLeftArrow = "\x1b[1;5D"
|
||||||
seqCtrlRightArrow = "\x1b[1;5C"
|
seqCtrlRightArrow = "\x1b[1;5C"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package readline
|
package readline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -69,40 +68,6 @@ func (rl *Instance) getCursorPos() (x int, y int) {
|
||||||
// This means that they are not used to keep any reference point when
|
// This means that they are not used to keep any reference point when
|
||||||
// when we internally move around clearning and printing things
|
// when we internally move around clearning and printing things
|
||||||
|
|
||||||
/*
|
|
||||||
func moveCursorUpBuffered(i int) {
|
|
||||||
if i < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(rl.bufferedOut, "\x1b[%dA", i)
|
|
||||||
}
|
|
||||||
|
|
||||||
func moveCursorDownBuffered(i int) {
|
|
||||||
if i < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(rl.bufferedOut, "\x1b[%dB", i)
|
|
||||||
}
|
|
||||||
|
|
||||||
func moveCursorForwardsBuffered(i int) {
|
|
||||||
if i < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(rl.bufferedOut, "\x1b[%dC", i)
|
|
||||||
}
|
|
||||||
|
|
||||||
func moveCursorUpBuffered(i int) {
|
|
||||||
if i < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(rl.bufferedOut, "\x1b[%dD", i)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func moveCursorUp(i int) {
|
func moveCursorUp(i int) {
|
||||||
if i < 1 {
|
if i < 1 {
|
||||||
return
|
return
|
||||||
|
@ -135,14 +100,6 @@ func moveCursorBackwards(i int) {
|
||||||
printf("\x1b[%dD", i)
|
printf("\x1b[%dD", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideCursor() {
|
|
||||||
print(seqHideCursor)
|
|
||||||
}
|
|
||||||
|
|
||||||
func unhideCursor() {
|
|
||||||
print(seqUnhideCursor)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *Instance) backspace(forward bool) {
|
func (rl *Instance) backspace(forward bool) {
|
||||||
if len(rl.line) == 0 || rl.pos == 0 {
|
if len(rl.line) == 0 || rl.pos == 0 {
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module github.com/maxlandon/readline
|
module github.com/maxlandon/readline
|
||||||
|
|
||||||
go 1.18
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
|
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package readline
|
package readline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -204,8 +203,6 @@ type Instance struct {
|
||||||
ViActionCallback func(ViAction, []string)
|
ViActionCallback func(ViAction, []string)
|
||||||
|
|
||||||
RawInputCallback func([]rune) // called on all input
|
RawInputCallback func([]rune) // called on all input
|
||||||
|
|
||||||
bufferedOut *bufio.Writer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInstance is used to create a readline instance and initialise it with sane defaults.
|
// NewInstance is used to create a readline instance and initialise it with sane defaults.
|
||||||
|
@ -254,8 +251,6 @@ func NewInstance() *Instance {
|
||||||
return suggs
|
return suggs
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.bufferedOut = bufio.NewWriter(os.Stdout)
|
|
||||||
|
|
||||||
// Registers
|
// Registers
|
||||||
rl.initRegisters()
|
rl.initRegisters()
|
||||||
|
|
||||||
|
|
|
@ -33,20 +33,19 @@ func (rl *Instance) GetLine() []rune {
|
||||||
func (rl *Instance) echo() {
|
func (rl *Instance) echo() {
|
||||||
|
|
||||||
// Then we print the prompt, and the line,
|
// Then we print the prompt, and the line,
|
||||||
hideCursor()
|
|
||||||
switch {
|
switch {
|
||||||
case rl.PasswordMask != 0:
|
case rl.PasswordMask != 0:
|
||||||
case rl.PasswordMask > 0:
|
case rl.PasswordMask > 0:
|
||||||
rl.bufprint(strings.Repeat(string(rl.PasswordMask), len(rl.line)) + " ")
|
print(strings.Repeat(string(rl.PasswordMask), len(rl.line)) + " ")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
// Go back to prompt position, and clear everything below
|
// Go back to prompt position, and clear everything below
|
||||||
moveCursorBackwards(GetTermWidth())
|
moveCursorBackwards(GetTermWidth())
|
||||||
moveCursorUp(rl.posY)
|
moveCursorUp(rl.posY)
|
||||||
|
print(seqClearScreenBelow)
|
||||||
|
|
||||||
// Print the prompt
|
// Print the prompt
|
||||||
rl.bufprint(string(rl.realPrompt))
|
print(string(rl.realPrompt))
|
||||||
|
|
||||||
// Assemble the line, taking virtual completions into account
|
// Assemble the line, taking virtual completions into account
|
||||||
var line []rune
|
var line []rune
|
||||||
|
@ -58,14 +57,11 @@ func (rl *Instance) echo() {
|
||||||
|
|
||||||
// Print the input line with optional syntax highlighting
|
// Print the input line with optional syntax highlighting
|
||||||
if rl.SyntaxHighlighter != nil {
|
if rl.SyntaxHighlighter != nil {
|
||||||
rl.bufprint(rl.SyntaxHighlighter(line))
|
print(rl.SyntaxHighlighter(line))
|
||||||
} else {
|
} else {
|
||||||
rl.bufprint(string(line))
|
print(string(line))
|
||||||
}
|
}
|
||||||
rl.bufprint(seqClearScreenBelow)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
rl.bufflush()
|
|
||||||
|
|
||||||
// Update references with new coordinates only now, because
|
// Update references with new coordinates only now, because
|
||||||
// the new line may be longer/shorter than the previous one.
|
// the new line may be longer/shorter than the previous one.
|
||||||
|
@ -76,7 +72,6 @@ func (rl *Instance) echo() {
|
||||||
moveCursorUp(rl.fullY)
|
moveCursorUp(rl.fullY)
|
||||||
moveCursorDown(rl.posY)
|
moveCursorDown(rl.posY)
|
||||||
moveCursorForwards(rl.posX)
|
moveCursorForwards(rl.posX)
|
||||||
unhideCursor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Instance) insert(r []rune) {
|
func (rl *Instance) insert(r []rune) {
|
||||||
|
@ -164,7 +159,7 @@ func (rl *Instance) clearLine() {
|
||||||
moveCursorForwards(rl.promptLen)
|
moveCursorForwards(rl.promptLen)
|
||||||
|
|
||||||
// Clear everything after & below the cursor
|
// Clear everything after & below the cursor
|
||||||
//print(seqClearScreenBelow)
|
print(seqClearScreenBelow)
|
||||||
|
|
||||||
// Real input line
|
// Real input line
|
||||||
rl.line = []rune{}
|
rl.line = []rune{}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (rl *Instance) RefreshPromptLog(log string) (err error) {
|
||||||
rl.stillOnRefresh = true
|
rl.stillOnRefresh = true
|
||||||
moveCursorUp(rl.infoY + rl.tcUsedY)
|
moveCursorUp(rl.infoY + rl.tcUsedY)
|
||||||
moveCursorBackwards(GetTermWidth())
|
moveCursorBackwards(GetTermWidth())
|
||||||
//print("\r\n" + seqClearScreenBelow)
|
print("\r\n" + seqClearScreenBelow)
|
||||||
|
|
||||||
// Print the log
|
// Print the log
|
||||||
fmt.Printf(log)
|
fmt.Printf(log)
|
||||||
|
@ -97,7 +97,7 @@ func (rl *Instance) RefreshPromptInPlace(prompt string) (err error) {
|
||||||
print(seqClearLine)
|
print(seqClearLine)
|
||||||
moveCursorUp(rl.infoY + rl.tcUsedY)
|
moveCursorUp(rl.infoY + rl.tcUsedY)
|
||||||
moveCursorBackwards(GetTermWidth())
|
moveCursorBackwards(GetTermWidth())
|
||||||
//print("\r\n" + seqClearScreenBelow)
|
print("\r\n" + seqClearScreenBelow)
|
||||||
|
|
||||||
// Add a new line if needed
|
// Add a new line if needed
|
||||||
if rl.Multiline {
|
if rl.Multiline {
|
||||||
|
@ -137,7 +137,7 @@ func (rl *Instance) RefreshPromptCustom(prompt string, offset int, clearLine boo
|
||||||
moveCursorUp(offset)
|
moveCursorUp(offset)
|
||||||
|
|
||||||
// Then clear everything below our new position
|
// Then clear everything below our new position
|
||||||
//print(seqClearScreenBelow)
|
print(seqClearScreenBelow)
|
||||||
|
|
||||||
// Update the prompt if a special has been passed.
|
// Update the prompt if a special has been passed.
|
||||||
if prompt != "" {
|
if prompt != "" {
|
||||||
|
|
|
@ -868,7 +868,7 @@ func (rl *Instance) escapeSeq(r []rune) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !rl.mainHist && rl.altHistory != nil {
|
if !rl.mainHist {
|
||||||
line, err = rl.altHistory.GetLine(rl.altHistory.Len() - 1)
|
line, err = rl.altHistory.GetLine(rl.altHistory.Len() - 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -276,14 +276,13 @@ func (rl *Instance) writeTabCompletion() {
|
||||||
// than what their MaxLength allows them to, cycling sometimes occur,
|
// than what their MaxLength allows them to, cycling sometimes occur,
|
||||||
// but does not fully clears itself: some descriptions are messed up with.
|
// but does not fully clears itself: some descriptions are messed up with.
|
||||||
// We always clear the screen as a result, between writings.
|
// We always clear the screen as a result, between writings.
|
||||||
//rl.bufprint(seqClearScreenBelow)
|
print(seqClearScreenBelow)
|
||||||
|
|
||||||
// Crop the completions so that it fits within our MaxTabCompleterRows
|
// Crop the completions so that it fits within our MaxTabCompleterRows
|
||||||
completions, rl.tcUsedY = rl.cropCompletions(completions)
|
completions, rl.tcUsedY = rl.cropCompletions(completions)
|
||||||
|
|
||||||
// Then we print all of them.
|
// Then we print all of them.
|
||||||
rl.bufprintF(completions)
|
fmt.Printf(completions)
|
||||||
rl.bufflush()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cropCompletions - When the user cycles through a completion list longer
|
// cropCompletions - When the user cycles through a completion list longer
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package readline
|
package readline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/text/width"
|
"golang.org/x/text/width"
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
// it should coordinate reprinting the input line, any Infos and completions
|
// it should coordinate reprinting the input line, any Infos and completions
|
||||||
// and manage to get back to the current (computed) cursor coordinates
|
// and manage to get back to the current (computed) cursor coordinates
|
||||||
func (rl *Instance) updateHelpers() {
|
func (rl *Instance) updateHelpers() {
|
||||||
print(seqHideCursor)
|
|
||||||
// Load all Infos & completions before anything.
|
// Load all Infos & completions before anything.
|
||||||
// Thus overwrites anything having been dirtily added/forced/modified, like rl.SetInfoText()
|
// Thus overwrites anything having been dirtily added/forced/modified, like rl.SetInfoText()
|
||||||
rl.getInfoText()
|
rl.getInfoText()
|
||||||
|
@ -28,7 +27,6 @@ func (rl *Instance) updateHelpers() {
|
||||||
// We are at the prompt line (with the latter
|
// We are at the prompt line (with the latter
|
||||||
// not printed yet), then reprint everything
|
// not printed yet), then reprint everything
|
||||||
rl.renderHelpers()
|
rl.renderHelpers()
|
||||||
print(seqUnhideCursor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabWidth = 4
|
const tabWidth = 4
|
||||||
|
@ -121,7 +119,7 @@ func (rl *Instance) clearHelpers() {
|
||||||
moveCursorForwards(rl.fullX)
|
moveCursorForwards(rl.fullX)
|
||||||
|
|
||||||
// Clear everything below
|
// Clear everything below
|
||||||
//print(seqClearScreenBelow)
|
print(seqClearScreenBelow)
|
||||||
|
|
||||||
// Go back to current cursor position
|
// Go back to current cursor position
|
||||||
moveCursorBackwards(GetTermWidth())
|
moveCursorBackwards(GetTermWidth())
|
||||||
|
@ -196,15 +194,3 @@ func (rl *Instance) renderHelpers() {
|
||||||
moveCursorUp(rl.fullY - rl.posY)
|
moveCursorUp(rl.fullY - rl.posY)
|
||||||
moveCursorForwards(rl.posX)
|
moveCursorForwards(rl.posX)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Instance) bufprintF(format string, a ...any) {
|
|
||||||
fmt.Fprintf(rl.bufferedOut, format, a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *Instance) bufprint(text string) {
|
|
||||||
fmt.Fprint(rl.bufferedOut, text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *Instance) bufflush() {
|
|
||||||
rl.bufferedOut.Flush()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue