Skip to content

Commit

Permalink
Plumb the new log-viewing widget into termshark's UI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gcla committed Jul 19, 2020
1 parent b090f05 commit 47d1dd7
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 3 deletions.
59 changes: 59 additions & 0 deletions ui/logsui.go
Original file line number Diff line number Diff line change
@@ -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:
26 changes: 26 additions & 0 deletions ui/logsui_windows.go
Original file line number Diff line number Diff line change
@@ -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:
30 changes: 27 additions & 3 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ' '),
Expand All @@ -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",
Expand Down Expand Up @@ -2484,7 +2508,7 @@ func Build() (*gowid.App, error) {
reallyQuit(app)
},
},
}
}...)

if PacketColorsSupported {
generalMenuItems = append(
Expand Down

0 comments on commit 47d1dd7

Please sign in to comment.