okami.mom/ultraviolet
git clone https://git.nkp.pet/okami.mom/ultraviolet
f72cc87
main
1package main 2 3import ( 4"context" 5"image/color" 6"log" 7 8 uv"github.com/charmbracelet/ultraviolet" 9"github.com/charmbracelet/ultraviolet/screen" 10) 11 12var ( 13gray = color.RGBA {R :104 ,G :104 ,B :104 ,A :255 }// #686868 14white = color.RGBA {R :180 ,G :180 ,B :180 ,A :255 }// #b4b4b4 15yellow = color.RGBA {R :180 ,G :180 ,B :16 ,A :255 }// #b4b416 16cyan = color.RGBA {R :16 ,G :180 ,B :180 ,A :255 }// #10b4b4 17green = color.RGBA {R :16 ,G :180 ,B :16 ,A :255 }// #10b410 18magenta = color.RGBA {R :180 ,G :16 ,B :180 ,A :255 }// #b410b4 19red = color.RGBA {R :180 ,G :16 ,B :16 ,A :255 }// #b41010 20blue = color.RGBA {R :16 ,G :16 ,B :180 ,A :255 }// #1010b4 21black = color.RGBA {R :16 ,G :16 ,B :16 ,A :255 }// #101010 22fullWhite = color.RGBA {R :235 ,G :235 ,B :235 ,A :255 }// #ebebeb 23fullBlack = color.RGBA {R :0 ,G :0 ,B :0 ,A :255 }// #000000 24lightBlack = color.RGBA {R :26 ,G :26 ,B :26 ,A :255 }// #1a1a1a 25purple = color.RGBA {R :72 ,G :16 ,B :116 ,A :255 }// #481074 26brown = color.RGBA {R :106 ,G :52 ,B :16 ,A :255 }// #6a3410 27navy = color.RGBA {R :16 ,G :70 ,B :106 ,A :255 }// #10466a 28) 29 30func main () { 31t := uv .DefaultTerminal () 32scr := t .Screen () 33 34if err := t .Start ();err != nil { 35log .Fatalf ("Error starting terminal: %v" ,err ) 36 } 37 38defer t .Stop () 39 40scr .EnterAltScreen () 41 42ctx ,cancel := context .WithCancel (context .Background ()) 43defer cancel () 44 45const barCount = 7 46const botBarCount = 6 47rowColors := [3 ][]color.RGBA { 480 : { 490 :white , 501 :yellow , 512 :cyan , 523 :green , 534 :magenta , 545 :red , 556 :blue , 56 }, 571 : { 580 :blue , 591 :black , 602 :magenta , 613 :black , 624 :cyan , 635 :black , 646 :white , 65 }, 662 : { 670 :navy , 681 :fullWhite , 692 :purple , 703 :black , 714 :black , 725 :black , 73 }, 74 } 75 76display := func () { 77screen .Clear (scr ) 78 79area := scr .Bounds () 80topRow := uv .Rect (0 ,0 ,area .Max .X , (area .Max .Y * 66 )/ 100 ) 81midRow := uv .Rect (0 ,topRow .Max .Y ,area .Max .X , (area .Max .Y * 8 )/ 100 ) 82botRow := uv .Rect (0 ,midRow .Max .Y ,area .Max .X , (area .Max .Y * 26 )/ 100 ) 83 84barWidth := topRow .Max .X / barCount 85for i ,row := range []uv.Rectangle { 86topRow ,midRow , 87 } { 88for j := 0 ;j < barCount ;j ++ { 89bar := uv .Rect (j * barWidth ,row .Min .Y , (j + 1 )* barWidth ,row .Max .Y ) 90cell := uv .EmptyCell 91cell .Style .Bg = rowColors [i ][j % len (rowColors [i ])] 92screen .FillArea (scr ,& cell ,bar ) 93 } 94 } 95 96botBarWidth := botRow .Max .X / botBarCount 97for i := 0 ;i < botBarCount ;i ++ { 98bar := uv .Rect (i * botBarWidth ,botRow .Min .Y , (i + 1 )* botBarWidth ,botRow .Max .Y ) 99cell := uv .EmptyCell 100cell .Style .Bg = rowColors [2 ][i % len (rowColors [2 ])] 101screen .FillArea (scr ,& cell ,bar ) 102 } 103 104// Special case for the before last bar 105const specialRow = 5 106subBarWidth := barWidth / 3 107for i := 0 ;i < 3 ;i ++ { 108bar := uv .Rect (specialRow * barWidth + i * subBarWidth ,botRow .Min .Y ,subBarWidth ,botRow .Max .Y ) 109cell := uv .EmptyCell 110switch i { 111case 0 : 112cell .Style .Bg = fullBlack 113case 1 : 114continue 115case 2 : 116cell .Style .Bg = lightBlack 117 } 118screen .FillArea (scr ,& cell ,bar ) 119 } 120 121scr .Render () 122scr .Flush () 123 } 124 125// initial render 126display () 127 128LOOP: 129for { 130select { 131case <- ctx .Done (): 132break LOOP 133case ev := <- t .Events (): 134switch ev := ev .(type ) { 135case uv.WindowSizeEvent : 136scr .Resize (ev .Width ,ev .Height ) 137display () 138case uv.KeyPressEvent : 139switch { 140case ev .MatchString ("q" ,"ctrl+c" ): 141cancel () 142 } 143 } 144 } 145 } 146}