Skip to content

Commit 34501ac

Browse files
committed
feat: basic support for new sappling vcs
1 parent 92aaa28 commit 34501ac

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

cmd/goprompt/cmdQuery.go

+51
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ const (
7777
_partVcsGitIdxTotal = "vcs_git_idx_total"
7878
_partVcsGitIdxIncluded = "vcs_git_idx_incl"
7979
_partVcsGitIdxExcluded = "vcs_git_idx_excl"
80+
81+
_partVcsSaplRev = "vcs_sapling_rev"
82+
_partVcsSaplNode = "vcs_sapling_node"
83+
_partVcsSaplBookmarks = "vcs_sapling_bookmarks"
84+
_partVcsSaplBookmarkActive = "vcs_sapling_bookmarks_active"
85+
_partVcsSaplBookmarksRemote = "vcs_sapling_bookmarks_remote"
8086
)
8187

8288
func handleQUIT() context.CancelFunc {
@@ -214,6 +220,51 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error {
214220
return nil
215221
})
216222

223+
tasks.Go(func(context.Context) error {
224+
subTasks := mkWgPool()
225+
defer subTasks.Wait()
226+
227+
saplingTemplate := `{rev}\t{node}\t{join(remotenames, "#")}\t{join(bookmarks, "#")}\t{activebookmark}\t{ifcontains(rev, revset("."), "@")}\n`
228+
229+
if _, err := stringExec("sl", "root"); err == nil {
230+
printPart(_partVcs, "sapling")
231+
} else {
232+
return nil
233+
}
234+
235+
subTasks.Go(func(ctx context.Context) error {
236+
if revInfo, err := stringExec("sl", "log", "-r", ".", "--template", saplingTemplate); err == nil {
237+
info := strings.Split(revInfo, "\t")
238+
printPart(_partVcsSaplRev, info[0])
239+
printPart(_partVcsSaplNode, info[1])
240+
printPart(_partVcsSaplBookmarks, info[3])
241+
if info[4] == "" {
242+
printPart(_partVcsSaplBookmarkActive, "@")
243+
} else {
244+
printPart(_partVcsSaplBookmarkActive, info[4])
245+
}
246+
printPart(_partVcsSaplBookmarksRemote, info[2])
247+
}
248+
249+
return nil
250+
})
251+
252+
253+
subTasks.Go(func(ctx context.Context) error {
254+
if saplStatus, err := stringExec("sl", "status"); err == nil {
255+
if len(saplStatus) == 0 {
256+
printPart(_partVcsDirty, 0)
257+
return nil
258+
}
259+
260+
printPart(_partVcsDirty, 1)
261+
}
262+
return nil
263+
})
264+
265+
return nil
266+
})
267+
217268
tasks.Go(func(context.Context) error {
218269
subTasks := mkWgPool()
219270
defer subTasks.Wait()

cmd/goprompt/cmdRender.go

+36
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,42 @@ func cmdRenderRun(_ *cobra.Command, _ []string) error {
137137
partsTop = append(partsTop, fmt.Sprintf("{%v}", strings.Join(gitParts, ":")))
138138
}
139139

140+
if p[_partVcs] == "sapling" {
141+
var saplParts []string
142+
143+
saplMark := "spl"
144+
saplMarkC := yellowC
145+
146+
saplBookmark := fmt.Sprint(p[_partVcsSaplBookmarkActive])
147+
saplBookmarkC := greenC
148+
149+
saplDirtyMarks := ""
150+
saplDirtyMarksC := redC
151+
if p[_partVcsDirty] != "" && p[_partVcsDirty] != "0" {
152+
saplDirtyMarks = "&"
153+
}
154+
155+
// distanceMarks := ""
156+
// distanceMarksC := magentaC
157+
158+
// distanceAhead := strInt(p[_partVcsLogAhead])
159+
// distanceBehind := strInt(p[_partVcsLogBehind])
160+
// if distanceAhead > 0 || distanceBehind > 0 {
161+
// distanceMarks = fmt.Sprintf("[+%v:-%v]", distanceAhead, distanceBehind)
162+
// }
163+
164+
saplParts = append(saplParts, saplMarkC(saplMark))
165+
saplParts = append(saplParts, saplBookmarkC(saplBookmark))
166+
if len(saplDirtyMarks) > 0 {
167+
saplParts = append(saplParts, saplDirtyMarksC(saplDirtyMarks))
168+
}
169+
// if len(distanceMarks) > 0 {
170+
// saplParts = append(saplParts, distanceMarksC(distanceMarks))
171+
// }
172+
173+
partsTop = append(partsTop, fmt.Sprintf("{%v}", strings.Join(saplParts, ":")))
174+
}
175+
140176
if p[_partVcsStg] != "" {
141177
var stgParts []string
142178

0 commit comments

Comments
 (0)