You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.5 KiB
98 lines
2.5 KiB
// Copyright 2018 Google Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
// simple demonstrates a simpler i3bar built using barista.
|
|
// Serves as a good starting point for building custom bars.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"time"
|
|
|
|
"barista.run"
|
|
"barista.run/bar"
|
|
"barista.run/base/click"
|
|
"barista.run/colors"
|
|
"barista.run/modules/clock"
|
|
"barista.run/modules/weather"
|
|
"barista.run/modules/weather/openweathermap"
|
|
"barista.run/outputs"
|
|
"barista.run/pango"
|
|
)
|
|
|
|
var startTaskManager = click.RunLeft("xfce4-taskmanager")
|
|
|
|
type autoWeatherProvider struct{
|
|
ApiKey string
|
|
}
|
|
|
|
func (a autoWeatherProvider) GetWeather() (weather.Weather, error) {
|
|
lat, lng, err := whereami()
|
|
if err != nil {
|
|
return weather.Weather{}, err
|
|
}
|
|
return openweathermap.
|
|
New(a.ApiKey).
|
|
Coords(lat, lng).
|
|
GetWeather()
|
|
}
|
|
|
|
func main() {
|
|
if err := setupOauthEncryption(); err != nil {
|
|
panic(fmt.Sprintf("Could not setup oauth token encryption: %v", err))
|
|
}
|
|
|
|
installNerdFontProvider("UbuntuMono Nerd Font")
|
|
configureColors()
|
|
|
|
localtime := clock.Local().
|
|
Output(time.Second, func(now time.Time) bar.Output {
|
|
return outputs.Pango(
|
|
pango.Icon("material-today").Color(colors.Scheme("dim-icon")),
|
|
now.Format("Mon Jan 2 "),
|
|
pango.Icon("material-access-time").Color(colors.Scheme("dim-icon")),
|
|
now.Format("15:04:05"),
|
|
).OnClick(click.RunLeft("gsimplecal"))
|
|
})
|
|
|
|
// Weather information comes from OpenWeatherMap.
|
|
// https://openweathermap.org/api.
|
|
wthr := weather.New(autoWeatherProvider{ApiKey: "%%OWM_API_KEY%%"}).Output(func(w weather.Weather) bar.Output {
|
|
return outputs.Pango(
|
|
pango.Text("Air").XSmall(), spacer,
|
|
pango.Textf("%.0f", math.Round(w.Temperature.Celsius())),
|
|
pango.Text("℃").XSmall(),
|
|
).OnClick(click.RunLeft("xdg-open", ))
|
|
|
|
})
|
|
|
|
batt := batterySegment()
|
|
vol := volumeSegment()
|
|
loadAvg := loadAverageSegment()
|
|
freeMem := memorySegment()
|
|
|
|
|
|
temp := cputempSegment()
|
|
|
|
panic(barista.Run(
|
|
temp,
|
|
freeMem,
|
|
loadAvg,
|
|
vol,
|
|
batt,
|
|
wthr,
|
|
localtime,
|
|
))
|
|
} |