Skip to content

Commit

Permalink
chore: support more terminal for cat logs on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
nange committed Mar 25, 2024
1 parent bb84bf0 commit 7f234b8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
27 changes: 19 additions & 8 deletions cmd/easyss/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,24 +303,35 @@ func (st *SysTray) AddExitMenu() *systray.MenuItem {
}

func (st *SysTray) catLog() error {
// Ref: https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.3
win := `-FilePath powershell -ArgumentList "-Command", "Get-Content", "-Wait", "-Tail 100", "%s"`
if runtime.GOOS == "windows" && util.SysSupportPowershell() {
win = fmt.Sprintf(win, st.ss.LogFilePath())
}

var linuxCmd []string
var winCmd string

if runtime.GOOS == "linux" {
title := "View Easyss Logs"
switch {
case util.SysSupportXTerminalEmulator():
linuxCmd = []string{"x-terminal-emulator", "-e", "tail", "-50f", st.ss.LogFilePath()}
case util.SysSupportGnomeTerminal():
linuxCmd = []string{"gnome-terminal", "--hide-menubar", "--geometry", "800*600", "--title", "View Easyss Logs", "--", "tail", "-50f", st.ss.LogFilePath()}
linuxCmd = []string{"gnome-terminal", "--hide-menubar", "--title", title, "--", "tail", "-50f", st.ss.LogFilePath()}
case util.SysSupportMateTerminal():
linuxCmd = []string{"gnome-terminal", "--hide-menubar", "--title", title, "--", "tail", "-50f", st.ss.LogFilePath()}
case util.SysSupportKonsole():
linuxCmd = []string{"konsole", "--hide-menubar", "-e", "tail", "-50f", st.ss.LogFilePath()}
case util.SysSupportXfce4Terminal():
linuxCmd = []string{"xfce4-terminal", "--hide-menubar", "--hide-toolbar", "--title", title, "--command", fmt.Sprintf("tail -50f %s", st.ss.LogFilePath())}
case util.SysSupportLxterminal():
linuxCmd = []string{"lxterminal", "--title", title, "--command", fmt.Sprintf("tail -50f %s", st.ss.LogFilePath())}
case util.SysSupportTerminator():
linuxCmd = []string{"terminator", "--title", title, "--command", fmt.Sprintf("tail -50f %s", st.ss.LogFilePath())}
}
} else if runtime.GOOS == "windows" {
// Ref: https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.3
win := `-FilePath powershell -ArgumentList "-Command", "Get-Content", "-Wait", "-Tail 100", "%s"`
winCmd = fmt.Sprintf(win, st.ss.LogFilePath())
}

cmdMap := map[string][]string{
"windows": {"powershell", "-Command", "Start-Process", win},
"windows": {"powershell", "-Command", "Start-Process", winCmd},
"linux": linuxCmd,
"darwin": {"open", "-a", "Console", st.ss.LogFilePath()},
}
Expand Down
20 changes: 20 additions & 0 deletions util/sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ func SysSupportGnomeTerminal() bool {
return SysSupport("gnome-terminal")
}

func SysSupportKonsole() bool {
return SysSupport("konsole")
}

func SysSupportXfce4Terminal() bool {
return SysSupport("xfce4-terminal")
}

func SysSupportLxterminal() bool {
return SysSupport("lxterminal")
}

func SysSupportMateTerminal() bool {
return SysSupport("mate-terminal")
}

func SysSupportTerminator() bool {
return SysSupport("terminator")
}

func SysSupport(bin string) bool {
lp, err := exec.LookPath(bin)
if lp != "" && err == nil {
Expand Down

0 comments on commit 7f234b8

Please sign in to comment.