Skip to content

Commit

Permalink
feat(edit): add multi line experimental support
Browse files Browse the repository at this point in the history
add multi line experimental support

Signed-off-by: mritd <[email protected]>
  • Loading branch information
mritd committed Jan 10, 2022
1 parent 10e604e commit 7d2081d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 62 deletions.
1 change: 1 addition & 0 deletions consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const commitMessageCheckFailedMsg = `
╰──────────────────────────────────────────────────╯`

const editorKey = "//edit"
const newLineKey = `\\n `

const luckyCommitEnv = "MMH_LUCKY_COMMIT"
const strictHostKey = "MMH_STRICT_HOST_KEY"
15 changes: 1 addition & 14 deletions ui_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,11 @@ func (m commitModel) commit() tea.Msg {
Type: m.views[SELECTOR].(selectorModel).choice,
Scope: m.views[INPUTS].(inputsModel).inputs[0].input.Value(),
Subject: m.views[INPUTS].(inputsModel).inputs[1].input.Value(),
Body: m.views[INPUTS].(inputsModel).inputs[2].input.Value(),
Body: strings.Replace(m.views[INPUTS].(inputsModel).inputs[2].input.Value(), newLineKey, "\n", -1),
Footer: m.views[INPUTS].(inputsModel).inputs[3].input.Value(),
SOB: sob,
}

//if msg.Scope == editorKey {
// msg.Scope = m.views[INPUTS].(inputsModel).editorInputs[0]
//}
//if msg.Subject == editorKey {
// msg.Subject = m.views[INPUTS].(inputsModel).editorInputs[1]
//}
//if msg.Body == editorKey {
// msg.Body = m.views[INPUTS].(inputsModel).editorInputs[2]
//}
//if msg.Footer == editorKey {
// msg.Footer = m.views[INPUTS].(inputsModel).editorInputs[3]
//}

if msg.Body == "" {
msg.Body = msg.Subject
}
Expand Down
48 changes: 0 additions & 48 deletions ui_commit_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,46 +72,6 @@ var (
spinnerMetaFrame3 = lipgloss.NewStyle().Foreground(lipgloss.Color("2")).Render("❯")
)

//
//func openEditor() string {
// f, err := ioutil.TempFile("", "gitflow-toolkit")
// if err != nil {
// panic(err)
// }
// defer func() {
// _ = f.Close()
// _ = os.Remove(f.Name())
// }()
//
// // write utf8 bom
// _, err = f.Write([]byte{0xEF, 0xBB, 0xBF})
// if err != nil {
// panic(err)
// }
//
// editor := "vim"
// if runtime.GOOS == "windows" {
// editor = "notepad"
// }
// if v := os.Getenv("VISUAL"); v != "" {
// editor = v
// } else if e := os.Getenv("EDITOR"); e != "" {
// editor = e
// }
//
// cmd := exec.Command(editor, f.Name())
// cmd.Stdin = os.Stdin
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
// _ = cmd.Run()
// raw, err := ioutil.ReadFile(f.Name())
// if err != nil {
// panic(err)
// }
//
// return strings.TrimSpace(string(bytes.TrimPrefix(raw, []byte{0xEF, 0xBB, 0xBF})))
//}

type inputWithCheck struct {
input textinput.Model
checker func(s string) error
Expand All @@ -121,7 +81,6 @@ type inputsModel struct {
focusIndex int
title string
inputs []inputWithCheck
//editorInputs []string
err error
errSpinner spinner.Model
editMode bool
Expand Down Expand Up @@ -154,12 +113,6 @@ func (m inputsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return m, func() tea.Msg { return done{nextView: COMMIT} }
}
//if m.inputs[m.focusIndex].input.Value() == editorKey {
// m.editMode = true
// m.editorInputs[m.focusIndex] = openEditor()
// m.editMode = false
// return m, tea.HideCursor
//}
fallthrough
case "tab", "down":
m.focusIndex++
Expand Down Expand Up @@ -256,7 +209,6 @@ func (m inputsModel) View() string {
func newInputsModel() inputsModel {
m := inputsModel{
inputs: make([]inputWithCheck, 4),
//editorInputs: make([]string, 4),
}

for i := range m.inputs {
Expand Down

0 comments on commit 7d2081d

Please sign in to comment.