opcal is a Go library and CLI tool designed to generate a One Page Calendar—a compact, easy-to-read calendar format that displays an entire year at a glance. This single-page layout makes it ideal for quickly referencing dates, planning events, or embedding a calendar into reports or applications. OpCal supports extensive customization options for colors, styles, and output formats, as well as localization, allowing you to tailor month and weekday names for different languages and regions.
- CLI Tool: Quickly generate a styled calendar for any year from the command line.
- Library Usage: Integrate OpCal into your Go projects as a library.
- Custom Styling: Customize colors, layout, and text labels.
- Multiple Formats: Output calendars as text, CSV, HTML, Markdown, or TSV.
- Highlight Current Year and Date: Automatically highlights the current month and date if applicable.
- Localization Support: Change month and weekday names for internationalization.
You can install the opcal
CLI tool directly using go install
:
-
Install the package:
go install github.com/d6o/opcal/cmd/opcal@latest
-
Make sure that GOPATH is in your PATH:
export PATH=$PATH:$(go env GOPATH)/bin
-
Execute opcal
opcal 1992
-
Clone the repository:
git clone https://github.com/d6o/opcal.git
-
Build the CLI tool:
cd opcal/cmd/opcal go build -o opcal
-
Call opcal
./opcal 2024
Add OpCal as a dependency in your project:
go get github.com/d6o/opcal
Run the tool from the command line:
./opcal [year]
- If no year is specified, the current year will be used.
Here is an example of using OpCal as a library in your Go project:
Add OpCal as a dependency in your project:
go get github.com/d6o/opcal
Example:
package main
import (
"fmt"
"github.com/d6o/opcal"
)
func main() {
year := 2025
calendar := opcal.New()
fmt.Println(calendar.String(year))
}
OpCal provides options for deep customization.
You can customize the colors and styles using the following methods:
SetColorMonthDefault(colors text.Colors)
SetColorMonthHighlight(colors text.Colors)
SetColorDayDefault(colors text.Colors)
SetColorDayHighlight(colors text.Colors)
SetColorWeekdayDefault(colors text.Colors)
SetColorWeekdayHighlight(colors text.Colors)
SetStyle(s table.Style)
You can localize the strings using the following methods:
SetShortMonths(months []string) error
SetShortWeekdays(weekdays []string) error
SetDateHeader(header string)
Here is an example of changing styles and text:
package main
import (
"fmt"
"github.com/d6o/opcal"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
)
func main() {
calendar := opcal.New()
calendar.SetShortMonths([]string{"Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dec"})
calendar.SetShortWeekdays([]string{"Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"})
calendar.SetColorDayDefault(text.Colors{text.FgBlue})
calendar.SetStyle(table.StyleColoredDark)
fmt.Println(calendar.String(2025))
}
OpCal supports the string, CSV, HTML, Markdown and TSV output formats.
calendar.String(2025)
calendar.CSV(2025)
calendar.HTML(2025)
calendar.Markdown(2025)
calendar.TSV(2025)
ErrInvalidShortMonths
: Returned when setting invalid month names.ErrInvalidShortWeekdays
: Returned when setting invalid weekday names.
If an invalid year is provided as a command-line argument, the tool defaults to the current year.
Contributions are welcome! Feel free to open issues or submit pull requests to improve OpCal.
- Create an issue to discuss about your idea
- [Fork it] (https://github.com/d6o/opcal/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Profit! ✅
OpCal is developed by d6o.
The MIT License (MIT)
Copyright (c) 2013-2018 Diego Siqueira
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.