9 Star 38 Fork 4

Gitee 极速下载/Sampler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/sqshq/sampler
克隆/下载
main.go 3.00 KB
一键复制 编辑 原始数据 按行查看 历史
sqshq 提交于 2019-12-21 21:05 . Remove all backend interaction
package main
import (
ui "github.com/gizak/termui/v3"
"github.com/sqshq/sampler/asset"
"github.com/sqshq/sampler/component"
"github.com/sqshq/sampler/component/asciibox"
"github.com/sqshq/sampler/component/barchart"
"github.com/sqshq/sampler/component/gauge"
"github.com/sqshq/sampler/component/layout"
"github.com/sqshq/sampler/component/runchart"
"github.com/sqshq/sampler/component/sparkline"
"github.com/sqshq/sampler/component/textbox"
"github.com/sqshq/sampler/config"
"github.com/sqshq/sampler/console"
"github.com/sqshq/sampler/data"
"github.com/sqshq/sampler/event"
"time"
)
type Starter struct {
player *asset.AudioPlayer
lout *layout.Layout
palette console.Palette
opt config.Options
cfg config.Config
}
func (s *Starter) startAll() []*data.Sampler {
samplers := make([]*data.Sampler, 0)
for _, c := range s.cfg.RunCharts {
cpt := runchart.NewRunChart(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers))
}
for _, c := range s.cfg.SparkLines {
cpt := sparkline.NewSparkLine(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers))
}
for _, c := range s.cfg.BarCharts {
cpt := barchart.NewBarChart(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers))
}
for _, c := range s.cfg.Gauges {
cpt := gauge.NewGauge(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Cur, c.Min, c.Max}, c.Triggers))
}
for _, c := range s.cfg.AsciiBoxes {
cpt := asciibox.NewAsciiBox(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers))
}
for _, c := range s.cfg.TextBoxes {
cpt := textbox.NewTextBox(c, s.palette)
samplers = append(samplers, s.start(cpt, cpt.Consumer, c.ComponentConfig, []config.Item{c.Item}, c.Triggers))
}
return samplers
}
func (s *Starter) start(drawable ui.Drawable, consumer *data.Consumer, componentConfig config.ComponentConfig, itemsConfig []config.Item, triggersConfig []config.TriggerConfig) *data.Sampler {
cpt := component.NewComponent(drawable, consumer, componentConfig)
triggers := data.NewTriggers(triggersConfig, consumer, s.opt, s.player)
items := data.NewItems(itemsConfig, *componentConfig.RateMs)
s.lout.AddComponent(cpt)
time.Sleep(10 * time.Millisecond) // desync coroutines
return data.NewSampler(consumer, items, triggers, s.opt, s.cfg.Variables, *componentConfig.RateMs)
}
func main() {
cfg, opt := config.LoadConfig()
console.Init()
defer console.Close()
player := asset.NewAudioPlayer()
if player != nil {
defer player.Close()
}
palette := console.GetPalette(*cfg.Theme)
lout := layout.NewLayout(component.NewStatusBar(*opt.ConfigFile, palette), component.NewMenu(palette))
starter := &Starter{player, lout, palette, opt, *cfg}
samplers := starter.startAll()
handler := event.NewHandler(samplers, opt, lout)
handler.HandleEvents()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/Sampler.git
git@gitee.com:mirrors/Sampler.git
mirrors
Sampler
Sampler
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385