Giter Site home page Giter Site logo

sasqwatch's Introduction

sasqwatch

Introducing sasqwatch, a modern take on the classic watch command using charm.sh libraries.

This is a simple implementation that showcases some of the capabilities of the bubletea libraries. It started with a basic idea, but as we discussed it with friends, it grew to become something more. The initial goal was to create a watch command version that would allow updates to be triggered at any time between the interval.

Main features

  • Provides main features of the original watch command
  • Trigger the command manually at any time between intervals
  • History feature to go back in time and navigate through recorded outputs
  • Records full command output, with vertical and horizontal scrolling support
  • Provides the ability to quickly copy command output to your clipboard
  • Allows you to set a custom title
  • Mouse support for scrolling

Demo

Installation

go install github.com/fabio42/sasqwatch@latest

sasqwatch is now also available through tea package manager:

sh <(curl tea.xyz) sasqwatch --help

Usage

sasqwatch is a tool to execute a program periodically, showing output fullscreen.

Usage:
  sasqwatch [flags] command

Flags:
  -g, --chgexit            Exit when output from command changes
  -D, --debug              Enable debug log
  -d, --diff               Highlight the differences between successive updates
  -e, --errexit            Exit if command has a non-zero exit
  -h, --help               help for sasqwatch
  -n, --interval uint      Specify update interval (default 2)
  -P, --permdiff           Highlight the differences between successive updates since the first iteration
  -r, --records uint       Specify how many stdout records are kept in memory (default 50)
  -T, --set-title string   Replace the hostname in the status bar by a custom string
  -v, --version            version for sasqwatch

Command History

sasqwatch keeps track of the command output history. You can use the [ and ] keys to travel back in time and visualize previous records. While viewing previous records, sasqwatch stops recording and enters pause mode. You can activate recording again by pressing the space key.

To save memory and control memory footprint, only changing outputs are recorded. In other words, if there are no changes in the stdout between two executions, it won't be recorded. By default, only the last 50 command outputs are recorded, but this can be adjusted using the -r <value> option.

A word on the implementation

Most of the complex problems were solved using the bubbletea libraries:

  • The command execution ticking system relies on the timer module, with precision at the second level. This could be improved, but this aspect has not been extensively tested yet, so you should not rely on this program if you need precise timing.

  • The command output handling relies on the viewport module. I encountered some limitations with the current version, which prevent horizontal scrolling and line wrapping. Therefore, a patched version of viewport is provided.

I attempted to implement line wrapping but faced challenges, particularly with very long outputs and handling of diffs. Eventually, I came across this patch provided by @tty2 that is still pending review. The patch is relatively easy to understand and works very well for the use case of sasqwatch. As a result, sasqwatch currently does not wrap lines, but it allows horizontal scrolling.

Finally, Windows is not supported at the moment, but this should be easy to implement!

sasqwatch's People

Contributors

fabio42 avatar fbessett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

daniejstriata

sasqwatch's Issues

optimal command to compile from source

What would be the preferred and optimal build command be?
I used:

GO111MODULE=on CGO_ENABLED=0 go build -v -trimpath -buildmode=pie -modcacherw -tags netgo -ldflags="-s -w"

I get a fairly decent binary at 5.1M but for instance I then cannot compress it with UPX.

not printing version number

I downloaded the source package and compiled. When I check the version it does not print the expected version:

$ sasqwatch -v
sasqwatch version (devel)

image

change interval from inside

Is it possible to add the functionality to change (increase/decrease) the interval once sasqwatch is running?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.