// 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/github" "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(), ) }) batt := batterySegment() vol := volumeSegment() loadAvg := loadAverageSegment() freeMem := memorySegment() temp := cputempSegment() ghNotify := github.New("%%GITHUB_CLIENT_ID%%", "%%GITHUB_CLIENT_SECRET%%"). Output(func(n github.Notifications) bar.Output { if n.Total() == 0 { return nil } out := outputs.Group( pango.Icon("fab-github"). Concat(spacer). ConcatTextf("%d", n.Total())) mentions := n["mention"] + n["team_mention"] if mentions > 0 { out.Append(spacer) out.Append(outputs.Pango( pango.Icon("mdi-bell"). ConcatTextf("%d", mentions)). Urgent(true)) } return out.Glue().OnClick( click.RunLeft("xdg-open", "https://github.com/notifications")) }) panic(barista.Run( temp, freeMem, loadAvg, ghNotify, vol, batt, wthr, localtime, )) }