-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
136 additions
and
45 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
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
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
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,15 @@ | ||
Der Cursor zeigt den aktuellen Bearbeitungs- und Navigationsbereich wie folgt an: | ||
"_"-Zeichen, "#"-Wörter, "$"-Sätze oder "¶"-Absätze. | ||
|
||
"|" zeigt bis zu vier Bearbeitungsmarkierungen an, die primäre und sekundäre Auswahlen definieren. | ||
Wenn nur eine Bearbeitungsmarkierung vorhanden ist, fungiert der Cursor als zweite Bearbeitungsmarkierung. | ||
Bei ausgewähltem Text tauscht die Leertaste die Auswahlen aus, | ||
"Eingabetaste"/"Strg-M" und "Entf"/"Strg-X" schneiden die primäre Auswahl aus. | ||
|
||
Mit den folgenden Tasten lassen sich spezielle Aktionen ausführen: | ||
"↑" Bereich vergrößern, "↓" Bereich verkleinern, "←" nach links bewegen, "→" nach rechts bewegen, | ||
"Rücktaste"/"Strg-H" vorhergehenden Text löschen, "Eingabetaste"/"Strg-M" neuer Absatz, | ||
"Einfügen"/"Strg-V" ausgeschnittenen Text einfügen, "Entf"/"Strg-X" Text beim Ausschneiden löschen, | ||
"Pos1"/"Strg-U" zum Anfang bewegen, "Ende"/"Strg-D" zum Ende bewegen, | ||
"Tab"/"Strg-I" Markierung setzen, "Umschalt-Tab" alle Markierungen abbrechen, "Strg-C" Text kopieren, | ||
"Strg-Q"/"Strg-W" beenden, "Strg-E" exportieren, "Strg-Z" rückgängig machen, "Strg-Y" wiederherstellen |
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,15 @@ | ||
カーソルは、編集とナビゲーションの現在の範囲を次のように表示します: | ||
「_」文字、「#」単語、「$」文、または「¶」段落。 | ||
|
||
「|」は、プライマリ選択とセカンダリ選択を定義する最大 4 つの編集マークを示します。 | ||
編集マークが 1 つしかない場合、カーソルは 2 番目の編集マークとして機能します。 | ||
テキストが選択されているときに「スペース」を押すと選択が交換され、 | ||
「Enter」/「Ctrl-M」または「Delete」/「Ctrl-X」を押すと選択が切り取られます。 | ||
|
||
以下のキーは特別なアクションを実行します: | ||
「↑」 範囲を拡大、「↓」 範囲を縮小、「←」 左に移動、「→」 右に移動、 | ||
「Backspace」/「Ctrl-H」 前のテキストを消去、「Enter」/「Ctrl-M」 新しい段落、 | ||
「Insert」/「Ctrl-V」 切り取ったテキストを挿入、「Delete」/「Ctrl-X」 切り取ったテキストの削除、 | ||
「Home」/「Ctrl-U」 先頭に移動、「End」/「Ctrl-D」 末尾に移動、 | ||
「Tab」/「Ctrl-I」 マークを設定、「Shift-Tab」 すべてのマークをクリア、「Ctrl-C」 テキストをコピー、 | ||
「Ctrl-Q」/「Ctrl-W」 終了、「Ctrl-E」 エクスポート、「Ctrl-Z」 元に戻す、「Ctrl-Y」 やり直し |
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,54 @@ | ||
package i18n | ||
|
||
import ( | ||
"embed" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/jeandeaual/go-locale" | ||
"github.com/rivo/uniseg" | ||
) | ||
|
||
//go:embed help.* text.* | ||
var translations embed.FS | ||
|
||
var ( | ||
HelpText []string | ||
HelpWidth int | ||
Text = make(map[string]string) | ||
TextWidth = make(map[string]int) | ||
) | ||
|
||
func init() { | ||
var err error | ||
var userLanguage string | ||
if userLanguage, err = locale.GetLanguage(); err != nil { | ||
userLanguage = "en" | ||
} | ||
|
||
var b []byte | ||
if b, err = translations.ReadFile("help." + userLanguage); err != nil { | ||
b, _ = translations.ReadFile("help.en") | ||
} | ||
|
||
HelpText = strings.Split(string(b), "\n") | ||
if len(HelpText[len(HelpText)-1]) == 0 { // Trim final blank line | ||
HelpText = slices.Delete(HelpText, len(HelpText)-1, len(HelpText)) | ||
} | ||
|
||
for _, l := range HelpText { | ||
HelpWidth = max(HelpWidth, uniseg.StringWidth(l)) | ||
} | ||
|
||
if b, err = translations.ReadFile("text." + userLanguage); err != nil { | ||
b, _ = translations.ReadFile("text.en") | ||
} | ||
|
||
s := strings.Split(string(b), "\n") | ||
for _, t := range s { | ||
k, v, _ := strings.Cut(t, "|") | ||
v = strings.Replace(v, `\n`, "\n", -1) | ||
Text[k] = v | ||
TextWidth[k] = uniseg.StringWidth(v) | ||
} | ||
} |
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,6 @@ | ||
confirm|Beenden bestätigen? | ||
cut|Ausschneiden: | ||
error|Fehler: | ||
help|ESC=Hilfe | ||
usage|Verwendung:\n %s [Dateiname]\n\nWenn kein Dateiname angegeben ist, wird standardmäßig „%s“ verwendet\n\nOptionen: | ||
version|Programmversion drucken und beenden |
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,6 @@ | ||
confirm|Confirm exit? | ||
cut|cut: | ||
error|Error: | ||
help|ESC=Help | ||
usage|Usage:\n %s [filename]\n\nIf filename is not provided, defaults to '%s'\n\nOptions: | ||
version|print program version and exit |
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,6 @@ | ||
confirm|終了を確認しますか? | ||
cut|カット: | ||
error|エラー: | ||
help|ESC=ヘルプ | ||
usage|使用方法:\n %s [ファイル名]\n\nファイル名が指定されていない場合は、デフォルトで '%s' になります\n\nオプション: | ||
version|プログラムのバージョンを印刷して終了します |
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,7 +1,7 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
_ "embed" | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
@@ -11,13 +11,11 @@ import ( | |
"time" | ||
|
||
"git.sericyb.com.au/jotty/edits" | ||
"git.sericyb.com.au/jotty/i18n" | ||
ps "git.sericyb.com.au/jotty/permascroll" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
//go:embed i18n | ||
var i18n embed.FS | ||
|
||
//go:generate sh -c "printf %s $(git describe --always --tags) > version.txt" | ||
//go:embed version.txt | ||
var version string | ||
|
@@ -47,12 +45,11 @@ var dispatch = map[tea.KeyType]func(){ | |
var ( | ||
exportPath = "jotty.txt" | ||
sx, sy int // screen dimensions | ||
vFlag = flag.Bool("version", false, "print program version and exit") | ||
) | ||
|
||
type model struct{ timer *time.Timer } | ||
|
||
func confirmExit() { edits.SetMode(edits.Quit, "Confirm exit?") } | ||
func confirmExit() { edits.SetMode(edits.Quit, i18n.Text["confirm"]) } | ||
func export() { edits.Export(exportPath) } | ||
func help() { edits.SetMode(edits.Help, "") } | ||
|
||
|
@@ -125,13 +122,13 @@ func cleanup() { | |
|
||
func usage() { | ||
fmt.Println("https://github.com/xanni/jotty ⓒ 2024 Andrew Pam <[email protected]>") | ||
fmt.Printf("\nUsage:\n %s [filename]\n\nIf filename is not provided, defaults to '%s'\n\nOptions:\n", | ||
filepath.Base(os.Args[0]), defaultName) | ||
fmt.Printf("\n"+i18n.Text["usage"]+"\n", filepath.Base(os.Args[0]), defaultName) | ||
flag.PrintDefaults() | ||
} | ||
|
||
func main() { | ||
flag.Usage = usage | ||
vFlag := flag.Bool("version", false, i18n.Text["version"]) | ||
flag.Parse() | ||
if *vFlag { | ||
println(filepath.Base(os.Args[0]) + " " + version) | ||
|
@@ -152,7 +149,6 @@ func main() { | |
} | ||
|
||
defer cleanup() | ||
edits.HelpText, _ = i18n.ReadFile("i18n/help.en") | ||
|
||
var m model | ||
m.timer = time.AfterFunc(syncDelay, func() { | ||
|