Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
hytromo committed Nov 8, 2022
0 parents commit df8dd1c
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
tags:
- "*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
with:
go-version: ">=1.19.3"
cache: true
- uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gomatrix-lite
.vscode
23 changes: 23 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
project_name: gomatrix-lite

builds:
- env: [CGO_ENABLED=0]
goos:
- linux
- windows
- darwin
goarch:
- amd64
- "386"
- arm
- arm64

nfpms:
- maintainer: Alexandros Solanos <solanosalex@gmail.com>
description: A matrix screen written in go
homepage: https://github.com/hytromo/gomatrix-lite
license: MIT
formats:
- deb
- rpm
- apk
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2022 Alexandros Solanos

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<h1 align="center">
gomatrix-lite
<br>
<br>
<img src="./usage.gif" alt="Showcase of using the tool" width="800">
<br>
<br>
</h1>

- [Usage](#usage)
- [Installation](#installation)
- [Purpose](#purpose)

# Usage

```
Usage of ./gomatrix-lite:
-c string
Matrix colors, can be up to 2 comma-separated colors for gradient (shorthand) (default "000000,00FF00")
-color string
Matrix colors, can be up to 2 comma-separated colors for gradient (default "000000,00FF00")
-v Show version (shorthand)
-version
Show version
```

Use the numbers 0-9 to control the speed. Use `q` or Ctrl+C to quit the app.

# Installation

Go over to the <a href="../../releases">Releases</a> and pick up a tarballed binary for your OS/arch, or a packaged file (deb, rpm etc)

# Purpose

This is obviously just a toy to see how easy it'd be to make something like `cmatrix` using Golang.

The name came from the fact that this seems to be lighter on the CPU usage from quite a few other implementations:

<h1 align="center">
<img src="./comparison.jpg" alt="CPU usage comparison between similar tools" width="800">
</h1>

The comparison was made with as similar settings as possible (speed, character set) and in terminals of the same dimensions.
Not much thought has gone into this project, it probably can be optimized more.
41 changes: 41 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"os"

"github.com/jessevdk/go-flags"
)

var opts struct {
Version bool `short:"v" long:"version" description:"Show version"`

Color string `short:"c" long:"color" description:"Matrix colors, can be up to 2 comma-separated colors for gradient" default:"000000,00FF00"`
}

type Config struct {
showVersion bool
colors Colors
}

func ParseArgs() Config {
_, err := flags.Parse(&opts)

if err != nil {
flagError := err.(*flags.Error)
if flagError.Type == flags.ErrHelp {
os.Exit(0)
} else if flagError.Type == flags.ErrUnknownFlag {
fmt.Println("Use --help to view all available options.")
os.Exit(0)
} else {
fmt.Printf("Error parsing flags: %s\n", err)
os.Exit(1)
}
}

return Config{
showVersion: opts.Version,
colors: parseColors(opts.Color),
}
}
46 changes: 46 additions & 0 deletions colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"strings"

"github.com/gdamore/tcell/v2"
)

type Colors struct {
start tcell.Color
end tcell.Color
}

func parseColors(color string) Colors {
var startColor tcell.Color
var endColor tcell.Color

if strings.Contains(color, ",") {
colorsArr := strings.Split(color, ",")

startColor = tcell.GetColor("#" + colorsArr[0])
endColor = tcell.GetColor("#" + colorsArr[1])
} else {
startColor = tcell.GetColor("#" + color)
endColor = startColor
}

return Colors{
start: startColor,
end: endColor,
}
}

func pickBetweenGradient(color1 tcell.Color, color2 tcell.Color, weight float32) tcell.Color {
w2 := weight
w1 := 1.0 - w2
c1r, c1g, c1b := color1.RGB()
c2r, c2g, c2b := color2.RGB()
rgb := tcell.NewRGBColor(
int32(float32(c1r)*w1+float32(c2r)*w2),
int32(float32(c1g)*w1+float32(c2g)*w2),
int32(float32(c1b)*w1+float32(c2b)*w2),
)

return rgb
}
Binary file added comparison.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/hytromo/gomatrix-lite

go 1.19

require (
github.com/gdamore/tcell/v2 v2.5.3
github.com/jessevdk/go-flags v1.5.0
)

require (
github.com/gdamore/encoding v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/text v0.3.7 // indirect
)
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.5.3 h1:b9XQrT6QGbgI7JvZOJXFNczOQeIYbo8BfeSMzt2sAV0=
github.com/gdamore/tcell/v2 v2.5.3/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 h1:saXMvIOKvRFwbOMicHXr0B1uwoxq9dGmLe5ExMES6c4=
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
73 changes: 73 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"fmt"
"log"

"os"

"github.com/gdamore/tcell/v2"
)

const VERSION = "0.0.1"

func eventLoop(xmax *int, ymax *int, waitTimeMs *int64, _s *tcell.Screen) {
s := *_s

for {
s.Show()

ev := s.PollEvent()

switch ev := ev.(type) {
case *tcell.EventResize:
s.Sync()
*xmax, *ymax = s.Size()
case *tcell.EventKey:
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
return
} else if ev.Key() == tcell.KeyCtrlL {
s.Sync()
} else if ev.Rune() == 'Q' || ev.Rune() == 'q' {
s.Fini()
os.Exit(0)
} else if ev.Rune() >= '0' && ev.Rune() <= '9' {
(*waitTimeMs) = 95 - int64((ev.Rune()-'0')*10)
}
}
}
}

func main() {
config := ParseArgs()

if config.showVersion {
fmt.Println(VERSION)
return
}

s, err := tcell.NewScreen()
if err != nil {
log.Fatalf("%+v", err)
}
if err := s.Init(); err != nil {
log.Fatalf("%+v", err)
}
s.EnablePaste()
s.Clear()

quit := func() {
maybePanic := recover()
s.Fini()
if maybePanic != nil {
panic(maybePanic)
}
}
defer quit()

xmax, ymax := s.Size()
var waitTime int64 = 35

go Matrix(&xmax, &ymax, &waitTime, &config.colors, &s)
eventLoop(&xmax, &ymax, &waitTime, &s)
}
Loading

0 comments on commit df8dd1c

Please sign in to comment.