From f65790dd3b4c8295fb0b8374fc9729f1e66eb20a Mon Sep 17 00:00:00 2001 From: Rienovie Date: Sat, 21 Dec 2024 23:26:50 -0500 Subject: [PATCH] Run command with Colon --- main.go | 20 ++++++++++++++------ uicomponents.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 66ccc2e..3f3d441 100644 --- a/main.go +++ b/main.go @@ -493,12 +493,20 @@ func main() { } else if key.Keyval() == gdk.KEY_Return { s := searchEntry.Text() if s != "" { - // Check if the search box content is an arithmetic expression. If so, display the result - // and copy to the clipboard with wl-copy. - result, e := expr.Eval(s, nil) - if e == nil { - log.Debugf("Setting up mathemathical operation result window. Operation: %s, result: %v", s, result) - setUpOperationResultWindow(s, fmt.Sprintf("%v", result)) + // Check if execute command input + if s[0] == ':' { + // Make sure there's something to run + if len(s) > 1 { + launch(substring(s, 1, -1), false, true) + } + } else { + // Check if the search box content is an arithmetic expression. If so, display the result + // and copy to the clipboard with wl-copy. + result, e := expr.Eval(s, nil) + if e == nil { + log.Debugf("Setting up mathemathical operation result window. Operation: %s, result: %v", s, result) + setUpOperationResultWindow(s, fmt.Sprintf("%v", result)) + } } } return true diff --git a/uicomponents.go b/uicomponents.go index ea51307..3f0f6c3 100644 --- a/uicomponents.go +++ b/uicomponents.go @@ -392,6 +392,28 @@ func setUpSearchEntry() *gtk.SearchEntry { phrase = sEntry.Text() if len(phrase) > 0 { + // Check if command input + if phrase[0] == ':' { + // Hide/Destroy everything except "execute command" + if appFlowBox != nil { + appFlowBox.Destroy() + } + if pinnedFlowBox.Visible() { + pinnedFlowBox.Hide() + } + if categoriesWrapper.Visible() { + categoriesWrapper.Hide() + } + + if len(phrase) > 1 { + statusLabel.SetText("Execute \"" + substring(phrase, 1, -1) + "\"") + } else { + statusLabel.SetText("Execute a command") + } + + return + } + // search apps appFlowBox = setUpAppsFlowBox(nil, phrase) @@ -452,6 +474,14 @@ func setUpSearchEntry() *gtk.SearchEntry { if fileSearchResultWrapper != nil { fileSearchResultWrapper.Hide() } + + if !pinnedFlowBox.Visible() { + pinnedFlowBox.ShowAll() + } + + if !categoriesWrapper.Visible() { + categoriesWrapper.ShowAll() + } } })