mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "bd4e0df7b32e43115ae307d7ff7b9ab0c8da3b11" and "1febe66f846f500f4bd07fe14691e3b359f49c80" have entirely different histories.
bd4e0df7b3
...
1febe66f84
|
@ -76,7 +76,6 @@ disables commands being added to history.
|
|||
random errors introduced with the new Lua runtime (see [#197])
|
||||
- `bait.release(name, catcher)` removes `handler` for the named `event`
|
||||
- `exec`, `clear` and `cat` builtin commands
|
||||
- `hilbish.cancel` hook
|
||||
|
||||
[#197]: https://github.com/Rosettea/Hilbish/issues/197
|
||||
|
||||
|
@ -152,12 +151,6 @@ an error of missing format variable
|
|||
- Fix an error with sh syntax in aliases
|
||||
- Prompt now works with east asian characters (CJK)
|
||||
- Set back the prompt to normal after exiting the continue prompt with ctrl-d
|
||||
- Users can now tab complete files with spaces while quoted or with escaped spaces.
|
||||
This means a query of `Files\ to\ ` with file names of `Files to tab complete` and `Files to complete`
|
||||
will result in the files being completed.
|
||||
- Fixed grid menu display if cell width ends up being the width of the terminal
|
||||
- Cut off item names in grid menu if its longer than cell width
|
||||
- Fix completion search menu disappearing
|
||||
|
||||
## [2.0.0-rc1] - 2022-09-14
|
||||
This is a pre-release version of Hilbish for testing. To see the changelog,
|
||||
|
|
67
complete.go
67
complete.go
|
@ -11,49 +11,15 @@ import (
|
|||
rt "github.com/arnodel/golua/runtime"
|
||||
)
|
||||
|
||||
var charEscapeMap = []string{
|
||||
"\"", "\\\"",
|
||||
"'", "\\'",
|
||||
"`", "\\`",
|
||||
" ", "\\ ",
|
||||
"(", "\\(",
|
||||
")", "\\)",
|
||||
"[", "\\[",
|
||||
"]", "\\]",
|
||||
"$", "\\$",
|
||||
"&", "\\&",
|
||||
"*", "\\*",
|
||||
">", "\\>",
|
||||
"<", "\\<",
|
||||
"|", "\\|",
|
||||
}
|
||||
var charEscapeMapInvert = invert(charEscapeMap)
|
||||
var escapeReplaer = strings.NewReplacer(charEscapeMap...)
|
||||
var escapeInvertReplaer = strings.NewReplacer(charEscapeMapInvert...)
|
||||
|
||||
func invert(m []string) []string {
|
||||
newM := make([]string, len(charEscapeMap))
|
||||
for i := range m {
|
||||
if (i + 1) % 2 == 0 {
|
||||
newM[i] = m[i - 1]
|
||||
newM[i - 1] = m[i]
|
||||
}
|
||||
}
|
||||
|
||||
return newM
|
||||
}
|
||||
|
||||
func splitForFile(str string) []string {
|
||||
func splitQuote(str string) []string {
|
||||
split := []string{}
|
||||
sb := &strings.Builder{}
|
||||
quoted := false
|
||||
|
||||
for i, r := range str {
|
||||
for _, r := range str {
|
||||
if r == '"' {
|
||||
quoted = !quoted
|
||||
sb.WriteRune(r)
|
||||
} else if r == ' ' && str[i - 1] == '\\' {
|
||||
sb.WriteRune(r)
|
||||
} else if !quoted && r == ' ' {
|
||||
split = append(split, sb.String())
|
||||
sb.Reset()
|
||||
|
@ -73,15 +39,12 @@ func splitForFile(str string) []string {
|
|||
}
|
||||
|
||||
func fileComplete(query, ctx string, fields []string) ([]string, string) {
|
||||
q := splitForFile(ctx)
|
||||
q := splitQuote(ctx)
|
||||
|
||||
return matchPath(q[len(q) - 1])
|
||||
}
|
||||
|
||||
func binaryComplete(query, ctx string, fields []string) ([]string, string) {
|
||||
q := splitForFile(ctx)
|
||||
query = q[len(q) - 1]
|
||||
|
||||
var completions []string
|
||||
|
||||
prefixes := []string{"./", "../", "/", "~/"}
|
||||
|
@ -91,7 +54,7 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) {
|
|||
if len(fileCompletions) != 0 {
|
||||
for _, f := range fileCompletions {
|
||||
fullPath, _ := filepath.Abs(util.ExpandHome(query + strings.TrimPrefix(f, filePref)))
|
||||
if err := findExecutable(escapeInvertReplaer.Replace(fullPath), false, true); err != nil {
|
||||
if err := findExecutable(fullPath, false, true); err != nil {
|
||||
continue
|
||||
}
|
||||
completions = append(completions, f)
|
||||
|
@ -103,6 +66,7 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) {
|
|||
|
||||
// filter out executables, but in path
|
||||
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
||||
// print dir to stderr for debugging
|
||||
// search for an executable which matches our query string
|
||||
if matches, err := filepath.Glob(filepath.Join(dir, query + "*")); err == nil {
|
||||
// get basename from matches
|
||||
|
@ -138,7 +102,6 @@ func matchPath(query string) ([]string, string) {
|
|||
var entries []string
|
||||
var baseName string
|
||||
|
||||
query = escapeInvertReplaer.Replace(query)
|
||||
path, _ := filepath.Abs(util.ExpandHome(filepath.Dir(query)))
|
||||
if string(query) == "" {
|
||||
// filepath base below would give us "."
|
||||
|
@ -166,7 +129,25 @@ func matchPath(query string) ([]string, string) {
|
|||
}
|
||||
|
||||
func escapeFilename(fname string) string {
|
||||
return escapeReplaer.Replace(fname)
|
||||
args := []string{
|
||||
"\"", "\\\"",
|
||||
"'", "\\'",
|
||||
"`", "\\`",
|
||||
" ", "\\ ",
|
||||
"(", "\\(",
|
||||
")", "\\)",
|
||||
"[", "\\[",
|
||||
"]", "\\]",
|
||||
"$", "\\$",
|
||||
"&", "\\&",
|
||||
"*", "\\*",
|
||||
">", "\\>",
|
||||
"<", "\\<",
|
||||
"|", "\\|",
|
||||
}
|
||||
|
||||
r := strings.NewReplacer(args...)
|
||||
return r.Replace(fname)
|
||||
}
|
||||
|
||||
func completionLoader(rtm *rt.Runtime) *rt.Table {
|
||||
|
|
|
@ -5,5 +5,3 @@
|
|||
|
||||
+ `hilbish.vimAction` -> actionName, args > Sent when the user does a "vim action," being something
|
||||
like yanking or pasting text. See `doc vim-mode actions` for more info.
|
||||
|
||||
+ `hilbish.cancel` > Sent when the user cancels their input with Ctrl-C.
|
||||
|
|
7
main.go
7
main.go
|
@ -181,14 +181,11 @@ input:
|
|||
break
|
||||
}
|
||||
if err != nil {
|
||||
if err == readline.CtrlC {
|
||||
fmt.Println("^C")
|
||||
hooks.Emit("hilbish.cancel")
|
||||
} else {
|
||||
if err != readline.CtrlC {
|
||||
// If we get a completely random error, print
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
// TODO: Halt if any other error occurs
|
||||
fmt.Println("^C")
|
||||
continue
|
||||
}
|
||||
var priv bool
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"github.com/rivo/uniseg"
|
||||
)
|
||||
|
||||
// initGrid - Grid display details. Called each time we want to be sure to have
|
||||
|
@ -14,8 +13,8 @@ func (g *CompletionGroup) initGrid(rl *Instance) {
|
|||
// Compute size of each completion item box
|
||||
tcMaxLength := 1
|
||||
for i := range g.Suggestions {
|
||||
if uniseg.GraphemeClusterCount(g.Suggestions[i]) > tcMaxLength {
|
||||
tcMaxLength = uniseg.GraphemeClusterCount(g.Suggestions[i])
|
||||
if len(g.Suggestions[i]) > tcMaxLength {
|
||||
tcMaxLength = len([]rune(g.Suggestions[i]))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +103,7 @@ func (g *CompletionGroup) writeGrid(rl *Instance) (comp string) {
|
|||
rl.tcUsedY++
|
||||
}
|
||||
|
||||
cellWidth := strconv.Itoa((GetTermWidth() / g.tcMaxX) - 4)
|
||||
cellWidth := strconv.Itoa((GetTermWidth() / g.tcMaxX) - 2)
|
||||
x := 0
|
||||
y := 1
|
||||
|
||||
|
@ -125,15 +124,7 @@ func (g *CompletionGroup) writeGrid(rl *Instance) (comp string) {
|
|||
comp += seqInvert
|
||||
}
|
||||
|
||||
sugg := g.Suggestions[i]
|
||||
if len(sugg) > GetTermWidth() {
|
||||
sugg = sugg[:GetTermWidth() - 4] + "..."
|
||||
}
|
||||
formatStr := "%-"+cellWidth+"s%s "
|
||||
if g.tcMaxX == 1 {
|
||||
formatStr = "%s%s"
|
||||
}
|
||||
comp += fmt.Sprintf(formatStr, fmtEscape(sugg), seqReset)
|
||||
comp += fmt.Sprintf("%-"+cellWidth+"s %s", fmtEscape(g.Suggestions[i]), seqReset)
|
||||
}
|
||||
|
||||
// Always add a newline to the group if the end if not punctuated with one
|
||||
|
|
|
@ -238,9 +238,7 @@ func (rl *Instance) Readline() (string, error) {
|
|||
|
||||
// Normal completion search does only refresh the search pattern and the comps
|
||||
if rl.modeTabFind || rl.modeAutoFind {
|
||||
rl.resetVirtualComp(false)
|
||||
rl.backspaceTabFind()
|
||||
rl.renderHelpers()
|
||||
rl.viUndoSkipAppend = true
|
||||
} else {
|
||||
// Always cancel any virtual completion
|
||||
|
@ -333,8 +331,6 @@ func (rl *Instance) Readline() (string, error) {
|
|||
|
||||
rl.modeTabFind = true
|
||||
rl.updateTabFind([]rune{})
|
||||
rl.updateVirtualComp()
|
||||
rl.renderHelpers()
|
||||
rl.viUndoSkipAppend = true
|
||||
|
||||
// Tab Completion & Completion Search ---------------------------------------------------------------
|
||||
|
@ -488,10 +484,7 @@ func (rl *Instance) Readline() (string, error) {
|
|||
if string(r[:i]) != seqShiftTab &&
|
||||
string(r[:i]) != seqForwards && string(r[:i]) != seqBackwards &&
|
||||
string(r[:i]) != seqUp && string(r[:i]) != seqDown {
|
||||
// basically only applies except on 1st ctrl r open
|
||||
// so if we have not explicitly selected something
|
||||
// (tabCompletionSelect is false) drop virtual completion
|
||||
rl.resetVirtualComp(!rl.tabCompletionSelect)
|
||||
rl.resetVirtualComp(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -524,9 +517,7 @@ func (rl *Instance) Readline() (string, error) {
|
|||
if rl.modeAutoFind || rl.modeTabFind {
|
||||
rl.resetVirtualComp(false)
|
||||
rl.updateTabFind(r[:i])
|
||||
rl.renderHelpers()
|
||||
rl.viUndoSkipAppend = true
|
||||
continue
|
||||
} else {
|
||||
rl.resetVirtualComp(false)
|
||||
rl.editorInput(r[:i])
|
||||
|
@ -613,7 +604,6 @@ func (rl *Instance) escapeSeq(r []rune) {
|
|||
case string(charEscape):
|
||||
switch {
|
||||
case rl.modeAutoFind:
|
||||
rl.resetVirtualComp(true)
|
||||
rl.resetTabFind()
|
||||
rl.clearHelpers()
|
||||
rl.resetTabCompletion()
|
||||
|
@ -621,7 +611,6 @@ func (rl *Instance) escapeSeq(r []rune) {
|
|||
rl.renderHelpers()
|
||||
|
||||
case rl.modeTabFind:
|
||||
rl.resetVirtualComp(true)
|
||||
rl.resetTabFind()
|
||||
rl.resetTabCompletion()
|
||||
|
||||
|
|
Loading…
Reference in New Issue