-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ZeusWPI/screen
Screen
- Loading branch information
Showing
12 changed files
with
338 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
golang 1.22.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"scc/screen" | ||
) | ||
|
||
func spotifyHandlerWrapper(app *screen.ScreenApp) func(*gin.Context) { | ||
return func(ctx *gin.Context) { | ||
spotifyHandler(app, ctx) | ||
} | ||
} | ||
|
||
func spotifyHandler(app *screen.ScreenApp, ctx *gin.Context) { | ||
b, _ := ctx.GetRawData() | ||
app.Spotify.Update(string(b)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package screen | ||
|
||
import ( | ||
"scc/utils" | ||
"time" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
) | ||
|
||
// Initial value, gets adjusted once it's known how much space is available | ||
var maxMessages = 20 | ||
|
||
type Cammie struct { | ||
screenApp *ScreenApp | ||
view *tview.TextView | ||
|
||
queue *utils.Queue[string] | ||
text string | ||
buffer string | ||
} | ||
|
||
func NewCammie(screenApp *ScreenApp) *Cammie { | ||
cammie := Cammie{ | ||
screenApp: screenApp, | ||
view: tview.NewTextView().SetWrap(true).SetWordWrap(true).SetText("pls"), | ||
|
||
queue: utils.NewQueue[string](maxMessages), | ||
} | ||
|
||
cammie.view.SetTitle(" Cammie ") | ||
cammie.view.SetBorder(true) | ||
cammie.view.SetTextColor(tcell.ColorOrange) | ||
cammie.view.SetBorderColor(tcell.ColorOrange) | ||
cammie.view.SetTitleColor(tcell.ColorOrange) | ||
|
||
return &cammie | ||
} | ||
|
||
func (cammie *Cammie) Run() { | ||
time.Sleep(5 * time.Second) | ||
|
||
_, _, _, h := cammie.view.GetInnerRect() | ||
cammie.queue.SetMaxSize(h) | ||
} | ||
|
||
func (cammie *Cammie) Update(message string) { | ||
cammie.queue.Enqueue(message) | ||
|
||
cammie.screenApp.execute(func() { | ||
cammie.screenApp.app.QueueUpdateDraw(func() { | ||
cammie.view.Clear() | ||
|
||
for _, message := range cammie.queue.Get() { | ||
cammie.view.Write([]byte(message + "\n")) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package screen | ||
|
||
import "github.com/rivo/tview" | ||
|
||
type Graph1 struct { | ||
ScreenApp *ScreenApp | ||
view *tview.Box | ||
} | ||
|
||
func NewGraph1(screenApp *ScreenApp) *Graph1 { | ||
graph1 := Graph1{ | ||
ScreenApp: screenApp, | ||
view: tview.NewBox().SetBorder(true).SetTitle("Graph 1"), | ||
} | ||
|
||
return &graph1 | ||
} | ||
|
||
func (graph1 *Graph1) Run() { | ||
} | ||
|
||
func (graph1 *Graph1) Update(text string) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package screen | ||
|
||
import "github.com/rivo/tview" | ||
|
||
type Graph2 struct { | ||
ScreenApp *ScreenApp | ||
view *tview.Box | ||
} | ||
|
||
func NewGraph2(screenApp *ScreenApp) *Graph2 { | ||
graph2 := Graph2{ | ||
ScreenApp: screenApp, | ||
view: tview.NewBox().SetBorder(true).SetTitle("Graph 1"), | ||
} | ||
|
||
return &graph2 | ||
} | ||
|
||
func (graph1 *Graph2) Run() { | ||
} | ||
|
||
func (graph1 *Graph2) Update(text string) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package screen | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/rivo/tview" | ||
) | ||
|
||
type ScreenApp struct { | ||
mu sync.Mutex | ||
app *tview.Application | ||
|
||
Spotify *Spotify | ||
Cammie *Cammie | ||
Graph1 *Graph1 | ||
Graph2 *Graph2 | ||
} | ||
|
||
type s_cammie struct { | ||
cammie *tview.TextView | ||
} | ||
|
||
func (screenApp *ScreenApp) execute(f func()) { | ||
screenApp.mu.Lock() | ||
defer screenApp.mu.Unlock() | ||
f() | ||
} | ||
|
||
func NewScreenApp() *ScreenApp { | ||
screen := ScreenApp{ | ||
app: tview.NewApplication(), | ||
} | ||
|
||
screen.Spotify = NewSpotify(&screen) | ||
screen.Cammie = NewCammie(&screen) | ||
screen.Graph1 = NewGraph1(&screen) | ||
screen.Graph2 = NewGraph2(&screen) | ||
|
||
screen.app.SetRoot(tview.NewFlex().SetDirection(tview.FlexRow). | ||
AddItem(screen.Spotify.view, 3, 2, false). | ||
AddItem(tview.NewFlex(). | ||
AddItem(screen.Cammie.view, 0, 5, false). | ||
AddItem(tview.NewFlex().SetDirection(tview.FlexRow). | ||
AddItem(screen.Graph1.view, 0, 1, false). | ||
AddItem(screen.Graph2.view, 0, 1, false), 0, 4, false), 0, 13, false), true). | ||
EnableMouse(true) | ||
|
||
return &screen | ||
} | ||
|
||
func Start(screen *ScreenApp) { | ||
|
||
go screen.Spotify.Run() | ||
go screen.Cammie.Run() | ||
go screen.Graph1.Run() | ||
go screen.Graph2.Run() | ||
|
||
if err := screen.app.Run(); err != nil { | ||
panic(err) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.