diff options
author | Joe <rbo@gmx.us> | 2024-05-13 20:20:20 +0200 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-05-13 20:20:20 +0200 |
commit | d89c910fb2b98d812e9142913e1cf5f86bae896f (patch) | |
tree | f7d9255b8a8aa6aa0f369cb09740cfba4db55420 | |
parent | k (diff) | |
download | hardflip-d89c910fb2b98d812e9142913e1cf5f86bae896f.tar.gz hardflip-d89c910fb2b98d812e9142913e1cf5f86bae896f.tar.bz2 hardflip-d89c910fb2b98d812e9142913e1cf5f86bae896f.tar.xz hardflip-d89c910fb2b98d812e9142913e1cf5f86bae896f.tar.zst hardflip-d89c910fb2b98d812e9142913e1cf5f86bae896f.zip |
fuck yea
-rw-r--r-- | src/c_hardflip.go | 12 | ||||
-rw-r--r-- | src/e_events.go | 49 |
2 files changed, 59 insertions, 2 deletions
diff --git a/src/c_hardflip.go b/src/c_hardflip.go index fb2d86a..9b1b5c0 100644 --- a/src/c_hardflip.go +++ b/src/c_hardflip.go @@ -51,6 +51,9 @@ package main +import "log" +import "os" + // the main data structure, holds up everything important type HardData struct { litems *ItemsList @@ -68,6 +71,15 @@ type HardData struct { } func main() { + // TODO: remove log for release + f, _ := os.OpenFile("/tmp/hflog", + os.O_RDWR | os.O_CREATE | os.O_APPEND, 0644) + defer f.Close() + log.SetOutput(f) + log.SetPrefix("") + log.SetFlags(0) + log.Println("--------------------") + data_dir := c_get_data_dir(nil) i_ui(data_dir) } diff --git a/src/e_events.go b/src/e_events.go index ace093b..9ee5df4 100644 --- a/src/e_events.go +++ b/src/e_events.go @@ -52,6 +52,7 @@ package main import ( + "log" "os" "github.com/gdamore/tcell/v2" @@ -278,6 +279,51 @@ func e_delete_host(data *HardData) error { return nil } +func e_tab_complete(buffer *Buffer) { + entries, err := os.ReadDir(".") + if err != nil { + return + } + var match []string + for _, v := range entries { + if len(v.Name()) >= buffer.len() && + v.Name()[:buffer.len()] == buffer.str() { + match = append(match, v.Name()) + } + } + log.Println(match) + if len(match) == 0 { + return + } else if len(match) == 1 { + buffer.insert(match[0]) + } else { + var common []rune + var shortest int = 1000000000 + var check bool = true + for _, v := range match { + if len(v) < shortest { + shortest = len(v) + } + } + for j := 0; j < shortest; j++ { + for i := 1; i < len(match); i++ { + if match[i][j] != match[i - 1][j] { + check = false + } + } + if check == false { + break + } else { + common = append(common, rune(match[0][j])) + } + } + if len(common) == 0 { + return + } + buffer.insert(string(common)) + } +} + func e_readline(event tcell.EventKey, buffer *Buffer) { if buffer.len() > 0 && (event.Key() == tcell.KeyBackspace || @@ -321,8 +367,7 @@ func e_readline(event tcell.EventKey, buffer *Buffer) { buffer.cursor += 1 } else if event.Key() == tcell.KeyTab || event.Key() == tcell.KeyCtrlI { - buffer.insert("hey go fuck yourself") - // TODO: here + e_tab_complete(buffer) } if buffer.cursor > buffer.len() { buffer.cursor = buffer.len() |