-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for switching note folders (#5)
- Loading branch information
Showing
4 changed files
with
215 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"github.com/qownnotes/qc/config" | ||
"github.com/qownnotes/qc/websocket" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
// switchCmd represents the switch command | ||
var switchCmd = &cobra.Command{ | ||
Use: "switch", | ||
Short: "Switch note folder", | ||
Long: `Switch to a different note folder`, | ||
RunE: switchNoteFolder, | ||
} | ||
|
||
func switchNoteFolder(cmd *cobra.Command, args []string) (err error) { | ||
flag := config.Flag | ||
|
||
if flag.Query != "" { | ||
id, _ := strconv.Atoi(flag.Query) | ||
fmt.Printf("Attempting to switch to note folder number %d!\n", id) | ||
websocket.SwitchNoteFolder(id) | ||
|
||
return nil | ||
} | ||
|
||
noteFolderData, currentId := websocket.FetchNoteFolderData() | ||
|
||
for _, noteFolder := range noteFolderData { | ||
currentText := "" | ||
|
||
if currentId == noteFolder.Id { | ||
currentText = "*" | ||
} | ||
|
||
fmt.Printf("%d%s) %s\n", noteFolder.Id, currentText, noteFolder.Name) | ||
} | ||
|
||
fmt.Print("\nSelect note folder to switch to: ") | ||
|
||
scanner := bufio.NewScanner(os.Stdin) | ||
scanner.Scan() | ||
|
||
if err := scanner.Err(); err != nil { | ||
fmt.Fprintln(os.Stderr, "Error reading standard input:", err) | ||
|
||
return nil | ||
} | ||
|
||
id, _ := strconv.Atoi(scanner.Text()) | ||
|
||
for _, noteFolder := range noteFolderData { | ||
if noteFolder.Id == id { | ||
websocket.SwitchNoteFolder(id) | ||
return nil | ||
} | ||
} | ||
|
||
fmt.Printf("Could not find note folder number %d!\n\n", id) | ||
|
||
return switchNoteFolder(cmd, args) | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(switchCmd) | ||
switchCmd.Flags().StringVarP(&config.Flag.Query, "folder", "f", "", | ||
`Note folder id to switch to`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package entity | ||
|
||
type SnippetInfo struct { | ||
Description string `json:"description"` | ||
Command string `json:"command"` | ||
Tag []string `json:"tags"` | ||
Output string `json:"output"` | ||
Description string `json:"description"` | ||
Command string `json:"command"` | ||
Tag []string `json:"tags"` | ||
Output string `json:"output"` | ||
} | ||
|
||
type NoteFolderInfo struct { | ||
Name string `json:"text"` | ||
Id int `json:"value"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters