From 47d1dd7ffec66586ab7e969c9cee610249febda1 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sun, 19 Jul 2020 18:13:50 -0400 Subject: [PATCH] Plumb the new log-viewing widget into termshark's UI Note that this is unix-only - there is no gowid terminal widget support on Windows :-/ You can open the termshark log from the minibuffer by using the logs command. --- ui/logsui.go | 59 ++++++++++++++++++++++++++++++++++++++++++++ ui/logsui_windows.go | 26 +++++++++++++++++++ ui/ui.go | 30 +++++++++++++++++++--- 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 ui/logsui.go create mode 100644 ui/logsui_windows.go diff --git a/ui/logsui.go b/ui/logsui.go new file mode 100644 index 0000000..b122e70 --- /dev/null +++ b/ui/logsui.go @@ -0,0 +1,59 @@ +// Copyright 2019-2020 Graham Clark. All rights reserved. Use of this source +// code is governed by the MIT license that can be found in the LICENSE +// file. + +// +build !windows + +// Package ui contains user-interface functions and helpers for termshark. +package ui + +import ( + "fmt" + + "github.com/gcla/gowid" + "github.com/gcla/gowid/widgets/holder" + "github.com/gcla/gowid/widgets/terminal" + "github.com/gcla/termshark/v2/widgets/logviewer" +) + +//====================================================================== + +// Dynamically load conv. If the convs window was last opened with a different filter, and the "limit to +// filter" checkbox is checked, then the data needs to be reloaded. +func openLogsUi(app gowid.IApp) { + logsUi, err := logviewer.New(gowid.WidgetCallback{"cb", + func(app gowid.IApp, w gowid.IWidget) { + t := w.(*terminal.Widget) + ecode := t.Cmd.ProcessState.ExitCode() + // -1 for signals - don't show an error for that + if ecode != 0 && ecode != -1 { + d := OpenError(fmt.Sprintf( + "Could not run logs viewer\n\n%s", t.Cmd.ProcessState), app) + d.OnOpenClose(gowid.MakeWidgetCallback("cb", func(app gowid.IApp, w gowid.IWidget) { + closeLogsUi(app) + })) + } else { + closeLogsUi(app) + } + }, + }, + ) + if err != nil { + OpenError(fmt.Sprintf("Error launching terminal: %v", err), app) + return + } + + logsView := holder.New(logsUi) + + appViewNoKeys.SetSubWidget(logsView, app) +} + +func closeLogsUi(app gowid.IApp) { + appViewNoKeys.SetSubWidget(mainView, app) +} + +//====================================================================== +// Local Variables: +// mode: Go +// fill-column: 110 +// End: diff --git a/ui/logsui_windows.go b/ui/logsui_windows.go new file mode 100644 index 0000000..759a416 --- /dev/null +++ b/ui/logsui_windows.go @@ -0,0 +1,26 @@ +// Copyright 2019-2020 Graham Clark. All rights reserved. Use of this source +// code is governed by the MIT license that can be found in the LICENSE +// file. + +// Package ui contains user-interface functions and helpers for termshark. +package ui + +import ( + "github.com/gcla/gowid" +) + +// Dynamically load conv. If the convs window was last opened with a different filter, and the "limit to +// filter" checkbox is checked, then the data needs to be reloaded. +func openLogsUi(app gowid.IApp) { +} + +func closeLogsUi(app gowid.IApp) { +} + +//====================================================================== + +//====================================================================== +// Local Variables: +// mode: Go +// fill-column: 110 +// End: diff --git a/ui/ui.go b/ui/ui.go index 9bd30a5..7c4c978 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -1000,6 +1000,15 @@ func lastLineMode(app gowid.IApp) { return nil })) + if runtime.GOOS != "windows" { + MiniBuffer.Register("logs", minibufferFn(func(gowid.IApp, ...string) error { + app.Run(gowid.RunFunction(func(app gowid.IApp) { + openLogsUi(app) + })) + return nil + })) + } + MiniBuffer.Register("set", setCommand{}) // read new pcap @@ -2393,7 +2402,9 @@ func Build() (*gowid.App, error) { //====================================================================== - generalMenuItems := []menuutil.SimpleMenuItem{ + generalMenuItems := make([]menuutil.SimpleMenuItem, 0) + + generalMenuItems = append(generalMenuItems, []menuutil.SimpleMenuItem{ menuutil.SimpleMenuItem{ Txt: "Refresh Screen", Key: gowid.MakeKeyExt2(0, tcell.KeyCtrlL, ' '), @@ -2420,7 +2431,20 @@ func Build() (*gowid.App, error) { generalMenu.Close(app) reallyClear(app) }, - }, + }}...) + + if runtime.GOOS != "windows" { + generalMenuItems = append(generalMenuItems, menuutil.SimpleMenuItem{ + Txt: "Show Log", + Key: gowid.MakeKey('l'), + CB: func(app gowid.IApp, w gowid.IWidget) { + analysisMenu.Close(app) + openLogsUi(app) + }, + }) + } + + generalMenuItems = append(generalMenuItems, []menuutil.SimpleMenuItem{ menuutil.MakeMenuDivider(), menuutil.SimpleMenuItem{ Txt: "Help", @@ -2484,7 +2508,7 @@ func Build() (*gowid.App, error) { reallyQuit(app) }, }, - } + }...) if PacketColorsSupported { generalMenuItems = append(