8000 #2 log window display by nicksinas · Pull Request #5 · Ovyl/tabouli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#2 log window display #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,38 @@ Tabouli, written in [Go](https://go.dev/), is also a delicious Mediterranean dis

Made @ [Ovyl](https://ovyl.io/) <img src="imgs/ovyl-logo.jpg" alt="ovyl" width="12"/>

![Screenshot](/imgs/tabouli-main.png)

## Installation
First, enable golang plugin:
`asdf plugin-add golang https://github.com/kennyp/asdf-golang.git`

Next, install latest:
`asdf install golang latest`

Lastly, Reshim:
`asdf reshim golang`

Note: We use `asdf` to manage golang installations below, but feel free to use whatever method you like.

## Modes
Tabouli supports 3 different modes, dependent on what parameters you pass in.
You can run with support for just a CLI:
`... tui --cli /com/port`
OR support for a CLI and Logs (this assumes 2 different com ports/uart connections):
`... tui --cli /com/port --logs /other/com/port`
OR support for just logs:
`... tui --logs /com/port`
This means there are 3 distinct UI's based on the parameters you pass in.

CLI + Logs:
![Screenshot](/imgs/tabouli-full-ui.png)
CLI Only:
![Screenshot](/imgs/tabouli-cli-only.png)
Logs Only:
![Screenshot](/imgs/tabouli-logs-only.png)

## Dependencies
Make sure you have Go installed. We use asdf. More information [here](/docs/asdf.md).

## Running From Source
Start by installing dependencies:
`go get`

Then run the TUI from Source:
`go run main.go tui /dev/tty.usbserial-2111430`
Then run the TUI from Source, if you just have a CLI device:
`go run main.go tui --cli /dev/tty.usbserial-123`

If you have both a CLI port and a separate logging port (optional):
`go run main.go tui --cli /dev/tty.usbserial-123 --logs /dev/tty.usbmodem666`

If you want to use tabouli to just display your logs if you don't have a CLI:
`go run main.go tui --logs /dev/tty.usbmodem666`

## Running A Binary
Create the binary:
Expand Down
12 changes: 9 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ func init() {
}

func argsValidation(cmd *cobra.Command, args []string) error {
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return err
}
// if err := cobra.ExactArgs(2)(cmd, args); err != nil {
// return err
// }
// var positionalArgs = cobra.RangeArgs(1, 2);
// if positionalArgs().Error() != nil {
// return err
// }

//log.Fatalf("args count: %d, args: %v", len(args), args)
return nil

}
100 changes: 78 additions & 22 deletions cmd/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"github.com/spf13/cobra"
)

var CLI_Port_Address string
var Logs_Port_Address string

// tuiCmd represents the tui command
var tuiCmd = &cobra.Command{
Use: "tui",
Expand All @@ -23,39 +26,92 @@ var tuiCmd = &cobra.Command{
`,
Args: argsValidation,
Run: func(cmd *cobra.Command, args []string) {
//address, baudrate, _ := getPathAndBaudrate(args[0])
config := serial.Config{
Address: args[0],
BaudRate: 9600,
DataBits: 8,
StopBits: 1,
Parity: "N",
Timeout: 1 * time.Second,
var cliPassed = false
var logsPassed = false
argCLI, err := cmd.Flags().GetString("cli")
if err == nil && argCLI != "" {
cliPassed = true
}
argLogs, err := cmd.Flags().GetString("logs")
if err == nil && argLogs != "" {
logsPassed = true
}
terminators := device.Terminators{}
terminators.RX = "\r\n"
terminators.TX = "\n"
defaults, err := defaults.NewDefaultFileHanlder()
if err == nil {
config.BaudRate = defaults.SerialBaudRate
config.DataBits = defaults.SerialDataBits
config.StopBits = defaults.SerialStopBits
config.Parity = defaults.SerialParity
terminators.TX = defaults.TXTerminator
terminators.RX = defaults.RXTerminator
} else {
defaults, err := defaults.NewDefaultFileHanlder(cliPassed, logsPassed)
if err != nil {
log.Fatal(err)
}

device := device.NewDevice(config, terminators)
ui := tui.CreateTView(device)
var cliDevice device.Device
var logDevice device.Device

if cliPassed {
cliDevice = initCLIDevice(argCLI, defaults)
// Attempt to open the cli device
if err := cliDevice.Open(); err != nil {
log.Fatalf("Failed to open com port for provided CLI device address: %v", err)
}
}
if logsPassed {
logDevice = initLogDevice(argLogs, defaults)
// Attempt to open the log device
if err := logDevice.Open(); err != nil {
log.Fatalf("Failed to open com port for provided Log device address: %v", err)
}
}

// Build the UI
ui := tui.CreateTView(cliDevice, logDevice)

// Setup callback for logs received from device to display in the UI
if logsPassed {
go logDevice.RXLogsForever(tui.LogToUI)
}

if err := ui.Run(); err != nil {
log.Fatal(err)
}
},
}

func initCLIDevice(addr string, defFile defaults.DefaultFile) device.Device {
config := serial.Config{
Address: addr,
BaudRate: defFile.CLIBaudRate,
DataBits: defFile.CLIDataBits,
StopBits: defFile.CLIStopBits,
Parity: defFile.CLIParity,
Timeout: 1 * time.Second,
}
terminators := device.Terminators{
TX: defFile.CLITXTerminator,
RX: defFile.CLIRXTerminator,
}

cliDevice := device.NewDevice(config, terminators)
return cliDevice
}

func initLogDevice(addr string, defFile defaults.DefaultFile) device.Device {
config := serial.Config{
Address: addr,
BaudRate: defFile.LogsBaudRate,
DataBits: defFile.LogsDataBits,
StopBits: defFile.LogsStopBits,
Parity: defFile.LogsParity,
Timeout: 1 * time.Second,
}
terminators := device.Terminators{
TX: defFile.LogsTXTerminator,
RX: defFile.LogsRXTerminator,
}

logsDevice := device.NewDevice(config, terminators)
return logsDevice
}

func init() {
tuiCmd.Flags().StringVarP(&CLI_Port_Address, "cli", "c", "", "-cli /dev/tty.usb123")
tuiCmd.Flags().StringVarP(&Logs_Port_Address, "logs", "l", "", "-logs /dev/tty.usb123")
rootCmd.AddCommand(tuiCmd)

// Here you will define your flags and configuration settings.
Expand Down
18 changes: 12 additions & 6 deletions defaults.yaml
Original file line number Diff line number Diff line 9E12 change
@@ -1,6 +1,12 @@
baud: 115200
data_bits: 8
stop_bits: 1
parity: N
tx_terminator: "\n"
rx_terminator: "\r\n"
cli_baud: 115200
cli_data_bits: 8
cli_stop_bits: 1
cli_parity: N
cli_tx_terminator: "\n"
cli_rx_terminator: "\r\n"
logs_baud: 115200
logs_data_bits: 8
logs_stop_bits: 1
logs_parity: N
logs_tx_terminator: "\n"
logs_rx_terminator: "\n"
9 changes: 9 additions & 0 deletions docs/asdf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Go Installation via ASDF
First, enable golang plugin:
`asdf plugin-add golang https://github.com/kennyp/asdf-golang.git`

Next, install latest:
`asdf install golang latest`

Lastly, Reshim:
`asdf reshim golang`
16 changes: 1 addition & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,19 @@ go 1.17
require (
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1
github.com/goburrow/serial v0.1.0
github.com/marcusolsson/tui-go v0.4.0
github.com/rivo/tview v0.0.0-20220103094729-e3413f80f77b
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.10.1
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading
0