Skip to content

Commit

Permalink
[feature]<main>: finish v1 ✨✨
Browse files Browse the repository at this point in the history
  • Loading branch information
o98k-ok committed Oct 13, 2024
1 parent e92a07f commit 06f60e8
Show file tree
Hide file tree
Showing 25 changed files with 224 additions and 38 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
all:
mkdir -p output
go build -o output/calendar cmd/main.go
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o output/calendar_arm64 cmd/main.go
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o output/calendar_amd64 cmd/main.go
makefat output/calendar output/calendar_*
rm -rf output/calendar_*
cp scripts/gridview.sh output/gridview.sh
cp scripts/note.sh output/note.sh
cp scripts/cat.sh output/cat.sh
cp -r icon output/icon

run: all
Expand Down
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# calendar
# calendar

## 如何使用

使用关键词`cal`打开日历

![alt text](./assets/calendar.png)


选择日期后,回车打开详情
![alt text](./assets/detail.png)

选择`记录`后,输入内容,回车保存
![alt text](./assets/note.png)


## 特性

- 支持公历、节日、假期
- 支持农历、节气
- 支持记录想法
- 支持回顾想法
- 支持想法整理
- 支持自定义主题色


## 开发

```
make clean && make
```


## 技术点

- Alfred GridView
- Alfred TextView
- Alfred ScriptFilter
Binary file added assets/calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/note.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 56 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
"time"

"github.com/o98k-ok/calendar/internal/date"
Expand Down Expand Up @@ -32,7 +33,61 @@ func main() {

app.Bind("detail", func(s []string) {
detail := date.Detail(s[0])
fmt.Println(detail.DetailFilter().Encode())
data, _ := json.Marshal(detail.DetailFilter())
fmt.Println(string(data))
})

app.Bind("note", func(s []string) {
filename := os.Getenv(date.NOTE_DATE_KEY)
if len(filename) == 0 {
alfred.Log("filename is empty")
return
}

newContent := strings.TrimSpace(s[0])
if len(newContent) != 0 && newContent != "note" {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
alfred.Log("open file error: %v", err)
return
}
defer file.Close()
if _, err := file.WriteString("* " + newContent + "\n"); err != nil {
alfred.Log("write file error: %v", err)
return
}
}

content, _ := os.ReadFile(filename)
result := map[string]any{
"variables": map[string]string{
date.NOTE_DATE_KEY: filename,
},
"response": string(content),
"behaviour": map[string]string{
"scroll": "end",
},
}
data, _ := json.Marshal(result)
fmt.Println(string(data))
})

app.Bind("cat", func(s []string) {
filename := os.Getenv(date.NOTE_DATE_KEY)
if len(filename) == 0 {
alfred.Log("filename is empty")
return
}

content, _ := os.ReadFile(filename)
result := map[string]any{
"response": string(content),
"variables": map[string]string{
"note_date": filename,
},
}
data, _ := json.Marshal(result)
fmt.Println(string(data))
})

app.Run(os.Args)
Expand Down
Binary file added icon/cat_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/cat_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/note_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/note_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/tidy_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon/tidy_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 110 additions & 34 deletions internal/date/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ type Date struct {
Holiday string
}

func noteKey(mode string) string {
return fmt.Sprintf("./icon/note_%s.png", mode)
}

func catKey(mode string) string {
return fmt.Sprintf("./icon/cat_%s.png", mode)
}

func tidyKey(mode string) string {
return fmt.Sprintf("./icon/tidy_%s.png", mode)
}

func dateKey(mode string) string {
return fmt.Sprintf("./icon/date_%s.png", mode)
}
Expand Down Expand Up @@ -72,61 +84,125 @@ func jieqiKey(mode string) string {
return fmt.Sprintf("./icon/blossom_%s.png", mode)
}

func (d Date) DetailFilter() *alfred.Items {
items := alfred.NewItems()
items.Append(&alfred.Item{
Title: d.Date,
SubTitle: DateTitle,
Arg: d.Date,
Icon: &alfred.Icon{Path: dateKey(MODE)},
func (d Date) DetailFilter() *Items {
items := &Items{}
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: "回顾",
SubTitle: "📖",
Arg: "cat",
Icon: &alfred.Icon{Path: catKey(MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
items.Append(&alfred.Item{
Title: d.Lunar,
SubTitle: LunarTitle,
Arg: d.Lunar,
Icon: &alfred.Icon{Path: lunarKey(MODE)},
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: "记录",
SubTitle: "📝",
Arg: "note",
Icon: &alfred.Icon{Path: noteKey(MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
items.Append(&alfred.Item{
Title: d.DayOfWeek,
SubTitle: WeekTitle,
Arg: d.DayOfWeek,
Icon: &alfred.Icon{Path: weekKey(d.DayOfWeek, MODE)},
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: d.Date,
SubTitle: DateTitle,
Arg: d.Date,
Icon: &alfred.Icon{Path: dateKey(MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: d.Lunar,
SubTitle: LunarTitle,
Arg: d.Lunar,
Icon: &alfred.Icon{Path: lunarKey(MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: d.DayOfWeek,
SubTitle: "😉",
Arg: d.DayOfWeek,
Icon: &alfred.Icon{Path: weekKey(d.DayOfWeek, MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
if d.Holiday != "" {
items.Append(&alfred.Item{
Title: d.Holiday,
SubTitle: HolidayTitle,
Arg: d.Holiday,
Icon: &alfred.Icon{Path: holidayKey(d.Holiday, MODE)},
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: d.Holiday,
SubTitle: HolidayTitle,
Arg: d.Holiday,
Icon: &alfred.Icon{Path: holidayKey(d.Holiday, MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
}
if d.Festivals != "" {
items.Append(&alfred.Item{
Title: d.Festivals,
SubTitle: FestivalTitle,
Arg: d.Festivals,
Icon: &alfred.Icon{Path: festivalKey(MODE)},
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: d.Festivals,
SubTitle: FestivalTitle,
Arg: d.Festivals,
Icon: &alfred.Icon{Path: festivalKey(MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
}
if d.Jieqi != "" {
items.Append(&alfred.Item{
Title: d.Jieqi,
SubTitle: JieqiTitle,
Arg: d.Jieqi,
Icon: &alfred.Icon{Path: jieqiKey(MODE)},
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: d.Jieqi,
SubTitle: JieqiTitle,
Arg: d.Jieqi,
Icon: &alfred.Icon{Path: jieqiKey(MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
}
items.Items = append(items.Items, &Item{
Item: alfred.Item{
Title: "整理",
SubTitle: "📑",
Arg: "tidy",
Icon: &alfred.Icon{Path: tidyKey(MODE)},
},
Variables: map[string]string{
NOTE_DATE_KEY: d.Date,
},
})
return items
}

type Items struct {
Items []*Item `json:"items"`
Preselect string `json:"preselect"`
Preselect string `json:"preselect,omitempty"`
}

type Item struct {
alfred.Item
Uid string `json:"uid"`
Uid string `json:"uid,omitempty"`
Variables map[string]string `json:"variables,omitempty"`
}

func (d Date) ToAlfredElem() *Item {
Expand Down
3 changes: 2 additions & 1 deletion internal/date/mode.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package date

var (
MODE = "white"
MODE = "white"
NOTE_DATE_KEY = "note_date"
)
Binary file modified output/calendar
Binary file not shown.
3 changes: 3 additions & 0 deletions output/cat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./calendar cat "$1"
Binary file added output/icon/cat_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/icon/cat_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/icon/note_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/icon/note_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/icon/tidy_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/icon/tidy_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions output/note.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

./calendar note "$1"
3 changes: 3 additions & 0 deletions scripts/cat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./calendar cat "$1"
3 changes: 3 additions & 0 deletions scripts/note.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

./calendar note "$1"

0 comments on commit 06f60e8

Please sign in to comment.