From 086d52d11fc23f9a8315cf6151c4c796f142c0cc Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 16 May 2024 20:20:20 +0200 Subject: better, now msg buff hopefully --- src/c_utils.go | 14 +++++++++++++- src/e_events.go | 11 +++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/c_utils.go b/src/c_utils.go index 2aa3fec..8d95a77 100644 --- a/src/c_utils.go +++ b/src/c_utils.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_utils.go - * Mon Jan 29 08:56:55 2024 + * Thu May 16 09:48:25 2024 * Joe * * core funcs @@ -220,3 +220,15 @@ func c_get_secret_gpg_keyring() [][2]string { keys = append(keys, [2]string{"plain", ""}) return keys } + +// reverses a string +// can be useful somehow +// found here really thanks yazu: +// https://stackoverflow.com/questions/1752414/how-to-reverse-a-string-in-go +func c_reverse_string(str string) string { + runes := []rune(str) + for i, j := 0, len(runes) - 1; i < j; i, j = i + 1, j - 1 { + runes[i], runes[j] = runes[j], runes[i] + } + return string(runes) +} diff --git a/src/e_events.go b/src/e_events.go index 9c4fd92..753b629 100644 --- a/src/e_events.go +++ b/src/e_events.go @@ -284,6 +284,8 @@ func e_tab_complete_get_current_dir(str, home_dir string) (string, string) { file := "" if len(str) == 0 { return dir, file + } else if len(str) >= 2 && str[0] == '~' && str[1] == '/' { + dir = home_dir + str[1:] } else if str[0] == '~' { dir = home_dir + str[1:] } else { @@ -296,7 +298,7 @@ func e_tab_complete_get_current_dir(str, home_dir string) (string, string) { file += string(dir[i]) dir = dir[:i] } - // TODO: file is reversed oh no + file = c_reverse_string(file) if stat, err := os.Stat(dir); err == nil && dir[len(dir) - 1] == '/' && stat.IsDir() == true { return dir, file @@ -323,8 +325,9 @@ func e_tab_complete(buffer *Buffer, home_dir string) { return } else if len(match) == 1 { buffer.insert(dir + match[0]) - if stat, err := os.Stat(match[0]); err == nil && stat.IsDir() == true { - buffer.insert(match[0] + "/") + if stat, err := os.Stat(dir + match[0]); err == nil && + stat.IsDir() == true { + buffer.insert(dir + match[0] + "/") } } else { var common []rune @@ -350,7 +353,7 @@ func e_tab_complete(buffer *Buffer, home_dir string) { if len(common) == 0 { return } - buffer.insert(string(common)) + buffer.insert(dir + string(common)) } } -- cgit v1.2.3