repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
style.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L99-L101
go
train
// Bold returns a new style based on s, with the bold attribute set // as requested.
func (s Style) Bold(on bool) Style
// Bold returns a new style based on s, with the bold attribute set // as requested. func (s Style) Bold(on bool) Style
{ return s.setAttrs(Style(AttrBold), on) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
style.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L105-L107
go
train
// Blink returns a new style based on s, with the blink attribute set // as requested.
func (s Style) Blink(on bool) Style
// Blink returns a new style based on s, with the blink attribute set // as requested. func (s Style) Blink(on bool) Style
{ return s.setAttrs(Style(AttrBlink), on) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
style.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L111-L113
go
train
// Dim returns a new style based on s, with the dim attribute set // as requested.
func (s Style) Dim(on bool) Style
// Dim returns a new style based on s, with the dim attribute set // as requested. func (s Style) Dim(on bool) Style
{ return s.setAttrs(Style(AttrDim), on) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
style.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L118-L120
go
train
// Reverse returns a new style based on s, with the reverse attribute set // as requested. (Reverse usually changes the foreground and background // colors.)
func (s Style) Reverse(on bool) Style
// Reverse returns a new style based on s, with the reverse attribute set // as requested. (Reverse usually changes the foreground and background // colors.) func (s Style) Reverse(on bool) Style
{ return s.setAttrs(Style(AttrReverse), on) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
style.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/style.go#L124-L126
go
train
// Underline returns a new style based on s, with the underline attribute set // as requested.
func (s Style) Underline(on bool) Style
// Underline returns a new style based on s, with the underline attribute set // as requested. func (s Style) Underline(on bool) Style
{ return s.setAttrs(Style(AttrUnderline), on) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
key.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/key.go#L206-L237
go
train
// Name returns a printable value or the key stroke. This can be used // when printing the event, for example.
func (ev *EventKey) Name() string
// Name returns a printable value or the key stroke. This can be used // when printing the event, for example. func (ev *EventKey) Name() string
{ s := "" m := []string{} if ev.mod&ModShift != 0 { m = append(m, "Shift") } if ev.mod&ModAlt != 0 { m = append(m, "Alt") } if ev.mod&ModMeta != 0 { m = append(m, "Meta") } if ev.mod&ModCtrl != 0 { m = append(m, "Ctrl") } ok := false if s, ok = KeyNames[ev.key]; !ok { if ev.key == KeyRune { s = "Rune[" + string(ev.ch) + "]" } else { s = fmt.Sprintf("Key[%d,%d]", ev.key, int(ev.ch)) } } if len(m) != 0 { if ev.mod&ModCtrl != 0 && strings.HasPrefix(s, "Ctrl-") { s = s[5:] } return fmt.Sprintf("%s+%s", strings.Join(m, "+"), s) } return s }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
key.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/key.go#L243-L259
go
train
// NewEventKey attempts to create a suitable event. It parses the various // ASCII control sequences if KeyRune is passed for Key, but if the caller // has more precise information it should set that specifically. Callers // that aren't sure about modifier state (most) should just pass ModNone.
func NewEventKey(k Key, ch rune, mod ModMask) *EventKey
// NewEventKey attempts to create a suitable event. It parses the various // ASCII control sequences if KeyRune is passed for Key, but if the caller // has more precise information it should set that specifically. Callers // that aren't sure about modifier state (most) should just pass ModNone. func NewEventKey(k Key, ch rune, mod ModMask) *EventKey
{ if k == KeyRune && (ch < ' ' || ch == 0x7f) { // Turn specials into proper key codes. This is for // control characters and the DEL. k = Key(ch) if mod == ModNone && ch < ' ' { switch Key(ch) { case KeyBackspace, KeyTab, KeyEsc, KeyEnter: // these keys are directly typeable without CTRL default: // most likely entered with a CTRL keypress mod = ModCtrl } } } return &EventKey{t: time.Now(), key: k, ch: ch, mod: mod} }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
colorfit.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/colorfit.go#L25-L52
go
train
// FindColor attempts to find a given color, or the best match possible for it, // from the palette given. This is an expensive operation, so results should // be cached by the caller.
func FindColor(c Color, palette []Color) Color
// FindColor attempts to find a given color, or the best match possible for it, // from the palette given. This is an expensive operation, so results should // be cached by the caller. func FindColor(c Color, palette []Color) Color
{ match := ColorDefault dist := float64(0) r, g, b := c.RGB() c1 := colorful.Color{ R: float64(r) / 255.0, G: float64(g) / 255.0, B: float64(b) / 255.0, } for _, d := range palette { r, g, b = d.RGB() c2 := colorful.Color{ R: float64(r) / 255.0, G: float64(g) / 255.0, B: float64(b) / 255.0, } // CIE94 is more accurate, but really really expensive. nd := c1.DistanceCIE76(c2) if math.IsNaN(nd) { nd = math.Inf(1) } if match == ColorDefault || nd < dist { match = d dist = nd } } return match }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
tscreen.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/tscreen.go#L39-L60
go
train
// NewTerminfoScreen returns a Screen that uses the stock TTY interface // and POSIX termios, combined with a terminfo description taken from // the $TERM environment variable. It returns an error if the terminal // is not supported for any reason. // // For terminals that do not support dynamic resize events, the $LINES // $COLUMNS environment variables can be set to the actual window size, // otherwise defaults taken from the terminal database are used.
func NewTerminfoScreen() (Screen, error)
// NewTerminfoScreen returns a Screen that uses the stock TTY interface // and POSIX termios, combined with a terminfo description taken from // the $TERM environment variable. It returns an error if the terminal // is not supported for any reason. // // For terminals that do not support dynamic resize events, the $LINES // $COLUMNS environment variables can be set to the actual window size, // otherwise defaults taken from the terminal database are used. func NewTerminfoScreen() (Screen, error)
{ ti, e := terminfo.LookupTerminfo(os.Getenv("TERM")) if e != nil { return nil, e } t := &tScreen{ti: ti} t.keyexist = make(map[Key]bool) t.keycodes = make(map[string]*tKeyCode) if len(ti.Mouse) > 0 { t.mouse = []byte(ti.Mouse) } t.prepareKeys() t.buildAcsMap() t.sigwinch = make(chan os.Signal, 10) t.fallback = make(map[rune]string) for k, v := range RuneFallbacks { t.fallback[k] = v } return t, nil }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
tscreen.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/tscreen.go#L660-L666
go
train
// writeString sends a string to the terminal. The string is sent as-is and // this function does not expand inline padding indications (of the form // $<[delay]> where [delay] is msec). In order to have these expanded, use // TPuts. If the screen is "buffering", the string is collected in a buffer, // with the intention that the entire buffer be sent to the terminal in one // write operation at some point later.
func (t *tScreen) writeString(s string)
// writeString sends a string to the terminal. The string is sent as-is and // this function does not expand inline padding indications (of the form // $<[delay]> where [delay] is msec). In order to have these expanded, use // TPuts. If the screen is "buffering", the string is collected in a buffer, // with the intention that the entire buffer be sent to the terminal in one // write operation at some point later. func (t *tScreen) writeString(s string)
{ if t.buffering { io.WriteString(&t.buf, s) } else { io.WriteString(t.out, s) } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
tscreen.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/tscreen.go#L846-L857
go
train
// buildAcsMap builds a map of characters that we translate from Unicode to // alternate character encodings. To do this, we use the standard VT100 ACS // maps. This is only done if the terminal lacks support for Unicode; we // always prefer to emit Unicode glyphs when we are able.
func (t *tScreen) buildAcsMap()
// buildAcsMap builds a map of characters that we translate from Unicode to // alternate character encodings. To do this, we use the standard VT100 ACS // maps. This is only done if the terminal lacks support for Unicode; we // always prefer to emit Unicode glyphs when we are able. func (t *tScreen) buildAcsMap()
{ acsstr := t.ti.AltChars t.acs = make(map[rune]string) for len(acsstr) > 2 { srcv := acsstr[0] dstv := string(acsstr[1]) if r, ok := vtACSNames[srcv]; ok { t.acs[r] = t.ti.EnterAcs + dstv + t.ti.ExitAcs } acsstr = acsstr[2:] } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
tscreen.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/tscreen.go#L954-L1069
go
train
// parseSgrMouse attempts to locate an SGR mouse record at the start of the // buffer. It returns true, true if it found one, and the associated bytes // be removed from the buffer. It returns true, false if the buffer might // contain such an event, but more bytes are necessary (partial match), and // false, false if the content is definitely *not* an SGR mouse record.
func (t *tScreen) parseSgrMouse(buf *bytes.Buffer) (bool, bool)
// parseSgrMouse attempts to locate an SGR mouse record at the start of the // buffer. It returns true, true if it found one, and the associated bytes // be removed from the buffer. It returns true, false if the buffer might // contain such an event, but more bytes are necessary (partial match), and // false, false if the content is definitely *not* an SGR mouse record. func (t *tScreen) parseSgrMouse(buf *bytes.Buffer) (bool, bool)
{ b := buf.Bytes() var x, y, btn, state int dig := false neg := false motion := false i := 0 val := 0 for i = range b { switch b[i] { case '\x1b': if state != 0 { return false, false } state = 1 case '\x9b': if state != 0 { return false, false } state = 2 case '[': if state != 1 { return false, false } state = 2 case '<': if state != 2 { return false, false } val = 0 dig = false neg = false state = 3 case '-': if state != 3 && state != 4 && state != 5 { return false, false } if dig || neg { return false, false } neg = true // stay in state case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': if state != 3 && state != 4 && state != 5 { return false, false } val *= 10 val += int(b[i] - '0') dig = true // stay in state case ';': if neg { val = -val } switch state { case 3: btn, val = val, 0 neg, dig, state = false, false, 4 case 4: x, val = val-1, 0 neg, dig, state = false, false, 5 default: return false, false } case 'm', 'M': if state != 5 { return false, false } if neg { val = -val } y = val - 1 motion = (btn & 32) != 0 btn &^= 32 if b[i] == 'm' { // mouse release, clear all buttons btn |= 3 btn &^= 0x40 t.buttondn = false } else if motion { /* * Some broken terminals appear to send * mouse button one motion events, instead of * encoding 35 (no buttons) into these events. * We resolve these by looking for a non-motion * event first. */ if !t.buttondn { btn |= 3 btn &^= 0x40 } } else { t.buttondn = true } // consume the event bytes for i >= 0 { buf.ReadByte() i-- } t.postMouseEvent(x, y, btn) return true, true } } // incomplete & inconclusve at this point return true, false }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
tscreen.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/tscreen.go#L1073-L1120
go
train
// parseXtermMouse is like parseSgrMouse, but it parses a legacy // X11 mouse record.
func (t *tScreen) parseXtermMouse(buf *bytes.Buffer) (bool, bool)
// parseXtermMouse is like parseSgrMouse, but it parses a legacy // X11 mouse record. func (t *tScreen) parseXtermMouse(buf *bytes.Buffer) (bool, bool)
{ b := buf.Bytes() state := 0 btn := 0 x := 0 y := 0 for i := range b { switch state { case 0: switch b[i] { case '\x1b': state = 1 case '\x9b': state = 2 default: return false, false } case 1: if b[i] != '[' { return false, false } state = 2 case 2: if b[i] != 'M' { return false, false } state++ case 3: btn = int(b[i]) state++ case 4: x = int(b[i]) - 32 - 1 state++ case 5: y = int(b[i]) - 32 - 1 for i >= 0 { buf.ReadByte() i-- } t.postMouseEvent(x, y, btn) return true, true } } return true, false }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L188-L196
go
train
// Resize adjusts the layout when the underlying View changes size.
func (b *BoxLayout) Resize()
// Resize adjusts the layout when the underlying View changes size. func (b *BoxLayout) Resize()
{ b.layout() // Now also let the children know we resized. for i := range b.cells { b.cells[i].widget.Resize() } b.PostEventWidgetResize(b) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L199-L211
go
train
// Draw is called to update the displayed content.
func (b *BoxLayout) Draw()
// Draw is called to update the displayed content. func (b *BoxLayout) Draw()
{ if b.view == nil { return } if b.changed { b.layout() } b.view.Fill(' ', b.style) for i := range b.cells { b.cells[i].widget.Draw() } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L219-L225
go
train
// SetView sets the View object used for the text bar.
func (b *BoxLayout) SetView(view View)
// SetView sets the View object used for the text bar. func (b *BoxLayout) SetView(view View)
{ b.changed = true b.view = view for _, c := range b.cells { c.view.SetView(view) } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L231-L245
go
train
// HandleEvent implements a tcell.EventHandler. The only events // we care about are Widget change events from our children. We // watch for those so that if the child changes, we can arrange // to update our layout.
func (b *BoxLayout) HandleEvent(ev tcell.Event) bool
// HandleEvent implements a tcell.EventHandler. The only events // we care about are Widget change events from our children. We // watch for those so that if the child changes, we can arrange // to update our layout. func (b *BoxLayout) HandleEvent(ev tcell.Event) bool
{ switch ev.(type) { case *EventWidgetContent: // This can only have come from one of our children. b.changed = true b.PostEventWidgetContent(b) return true } for _, c := range b.cells { if c.widget.HandleEvent(ev) { return true } } return false }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L248-L260
go
train
// AddWidget adds a widget to the end of the BoxLayout.
func (b *BoxLayout) AddWidget(widget Widget, fill float64)
// AddWidget adds a widget to the end of the BoxLayout. func (b *BoxLayout) AddWidget(widget Widget, fill float64)
{ c := &boxLayoutCell{ widget: widget, fill: fill, view: NewViewPort(b.view, 0, 0, 0, 0), } widget.SetView(c.view) b.cells = append(b.cells, c) b.changed = true widget.Watch(b) b.layout() b.PostEventWidgetContent(b) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L265-L284
go
train
// InsertWidget inserts a widget at the given offset. Offset 0 is the // front. If the index is longer than the number of widgets, then it // just gets appended to the end.
func (b *BoxLayout) InsertWidget(index int, widget Widget, fill float64)
// InsertWidget inserts a widget at the given offset. Offset 0 is the // front. If the index is longer than the number of widgets, then it // just gets appended to the end. func (b *BoxLayout) InsertWidget(index int, widget Widget, fill float64)
{ c := &boxLayoutCell{ widget: widget, fill: fill, view: NewViewPort(b.view, 0, 0, 0, 0), } c.widget.SetView(c.view) if index < 0 { index = 0 } if index > len(b.cells) { index = len(b.cells) } b.cells = append(b.cells, c) copy(b.cells[index+1:], b.cells[index:]) b.cells[index] = c widget.Watch(b) b.layout() b.PostEventWidgetContent(b) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L287-L302
go
train
// RemoveWidget removes a Widget from the layout.
func (b *BoxLayout) RemoveWidget(widget Widget)
// RemoveWidget removes a Widget from the layout. func (b *BoxLayout) RemoveWidget(widget Widget)
{ changed := false for i := 0; i < len(b.cells); i++ { if b.cells[i].widget == widget { b.cells = append(b.cells[:i], b.cells[i+1:]...) changed = true } } if !changed { return } b.changed = true widget.Unwatch(b) b.layout() b.PostEventWidgetContent(b) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L305-L311
go
train
// Widgets returns the list of Widgets for this BoxLayout.
func (b *BoxLayout) Widgets() []Widget
// Widgets returns the list of Widgets for this BoxLayout. func (b *BoxLayout) Widgets() []Widget
{ w := make([]Widget, 0, len(b.cells)) for _, c := range b.cells { w = append(w, c.widget) } return w }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L314-L320
go
train
// SetOrientation sets the orientation as either Horizontal or Vertical.
func (b *BoxLayout) SetOrientation(orient Orientation)
// SetOrientation sets the orientation as either Horizontal or Vertical. func (b *BoxLayout) SetOrientation(orient Orientation)
{ if b.orient != orient { b.orient = orient b.changed = true b.PostEventWidgetContent(b) } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/boxlayout.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/boxlayout.go#L323-L326
go
train
// SetStyle sets the style used.
func (b *BoxLayout) SetStyle(style tcell.Style)
// SetStyle sets the style used. func (b *BoxLayout) SetStyle(style tcell.Style)
{ b.style = style b.PostEventWidgetContent(b) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
console_win.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/console_win.go#L445-L447
go
train
// NB: All Windows platforms are little endian. We assume this // never, ever change. The following code is endian safe. and does // not use unsafe pointers.
func getu32(v []byte) uint32
// NB: All Windows platforms are little endian. We assume this // never, ever change. The following code is endian safe. and does // not use unsafe pointers. func getu32(v []byte) uint32
{ return uint32(v[0]) + (uint32(v[1]) << 8) + (uint32(v[2]) << 16) + (uint32(v[3]) << 24) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
console_win.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/console_win.go#L459-L474
go
train
// Convert windows dwControlKeyState to modifier mask
func mod2mask(cks uint32) ModMask
// Convert windows dwControlKeyState to modifier mask func mod2mask(cks uint32) ModMask
{ mm := ModNone // Left or right control if (cks & (0x0008 | 0x0004)) != 0 { mm |= ModCtrl } // Left or right alt if (cks & (0x0002 | 0x0001)) != 0 { mm |= ModAlt } // Any shift if (cks & 0x0010) != 0 { mm |= ModShift } return mm }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
console_win.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/console_win.go#L652-L667
go
train
// Windows uses RGB signals
func mapColor2RGB(c Color) uint16
// Windows uses RGB signals func mapColor2RGB(c Color) uint16
{ winLock.Lock() if v, ok := winColors[c]; ok { c = v } else { v = FindColor(c, winPalette) winColors[c] = v c = v } winLock.Unlock() if vc, ok := vgaColors[c]; ok { return vc } return 0 }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
console_win.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/console_win.go#L670-L703
go
train
// Map a tcell style to Windows attributes
func (s *cScreen) mapStyle(style Style) uint16
// Map a tcell style to Windows attributes func (s *cScreen) mapStyle(style Style) uint16
{ f, b, a := style.Decompose() fa := s.oscreen.attrs & 0xf ba := (s.oscreen.attrs) >> 4 & 0xf if f != ColorDefault { fa = mapColor2RGB(f) } if b != ColorDefault { ba = mapColor2RGB(b) } var attr uint16 // We simulate reverse by doing the color swap ourselves. // Apparently windows cannot really do this except in DBCS // views. if a&AttrReverse != 0 { attr = ba attr |= (fa << 4) } else { attr = fa attr |= (ba << 4) } if a&AttrBold != 0 { attr |= 0x8 } if a&AttrDim != 0 { attr &^= 0x8 } if a&AttrUnderline != 0 { // Best effort -- doesn't seem to work though. attr |= 0x8000 } // Blink is unsupported return attr }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/sstext.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstext.go#L52-L88
go
train
// SetMarkup sets the text used for the string. It applies markup as follows // (modeled on tcsh style prompt markup): // // * %% - emit a single % in current style // * %N - normal style // * %A - alternate style // * %S - start standout (reverse) style // * %B - start bold style // * %U - start underline style // // Other styles can be set using %<rune>, if styles are registered. // Upper case characters and punctuation are reserved for use by the system. // Lower case are available for use by the user. (Users may define mappings // for upper case letters to override system defined styles.) // // Note that for simplicity, combining styles is not supported. By default // the alternate style is the same as standout (reverse) mode. // // Arguably we could have used Markdown syntax instead, but properly doing all // of Markdown is not trivial, and these escape sequences make it clearer that // we are not even attempting to do that.
func (t *SimpleStyledText) SetMarkup(s string)
// SetMarkup sets the text used for the string. It applies markup as follows // (modeled on tcsh style prompt markup): // // * %% - emit a single % in current style // * %N - normal style // * %A - alternate style // * %S - start standout (reverse) style // * %B - start bold style // * %U - start underline style // // Other styles can be set using %<rune>, if styles are registered. // Upper case characters and punctuation are reserved for use by the system. // Lower case are available for use by the user. (Users may define mappings // for upper case letters to override system defined styles.) // // Note that for simplicity, combining styles is not supported. By default // the alternate style is the same as standout (reverse) mode. // // Arguably we could have used Markdown syntax instead, but properly doing all // of Markdown is not trivial, and these escape sequences make it clearer that // we are not even attempting to do that. func (t *SimpleStyledText) SetMarkup(s string)
{ markup := []rune(s) styl := make([]tcell.Style, 0, len(markup)) text := make([]rune, 0, len(markup)) style := t.styles['N'] esc := false for _, r := range markup { if esc { esc = false switch r { case '%': text = append(text, '%') styl = append(styl, style) default: style = t.styles[r] } continue } switch r { case '%': esc = true continue default: text = append(text, r) styl = append(styl, style) } } t.Text.SetText(string(text)) for i, s := range styl { t.SetStyleAt(i, s) } t.markup = markup }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/sstext.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstext.go#L95-L102
go
train
// Registers a style for the given rune. This style will be used for // text marked with %<r>. See SetMarkup() for more detail. Note that // this must be done before using any of the styles with SetMarkup(). // Only letters may be used when registering styles, and be advised that // the system may have predefined uses for upper case letters.
func (t *SimpleStyledText) RegisterStyle(r rune, style tcell.Style)
// Registers a style for the given rune. This style will be used for // text marked with %<r>. See SetMarkup() for more detail. Note that // this must be done before using any of the styles with SetMarkup(). // Only letters may be used when registering styles, and be advised that // the system may have predefined uses for upper case letters. func (t *SimpleStyledText) RegisterStyle(r rune, style tcell.Style)
{ if r == 'N' { t.Text.SetStyle(style) } if unicode.IsLetter(r) { t.styles[r] = style } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/sstext.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstext.go#L107-L109
go
train
// LookupStyle returns the style registered for the given rune. // Returns tcell.StyleDefault if no style was previously registered // for the rune.
func (t *SimpleStyledText) LookupStyle(r rune) tcell.Style
// LookupStyle returns the style registered for the given rune. // Returns tcell.StyleDefault if no style was previously registered // for the rune. func (t *SimpleStyledText) LookupStyle(r rune) tcell.Style
{ return t.styles[r] }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/sstext.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/sstext.go#L117-L126
go
train
// NewSimpleStyledText creates an empty Text.
func NewSimpleStyledText() *SimpleStyledText
// NewSimpleStyledText creates an empty Text. func NewSimpleStyledText() *SimpleStyledText
{ ss := &SimpleStyledText{} // Create map and establish default styles. ss.styles = make(map[rune]tcell.Style) ss.styles['N'] = tcell.StyleDefault ss.styles['S'] = tcell.StyleDefault.Reverse(true) ss.styles['U'] = tcell.StyleDefault.Underline(true) ss.styles['B'] = tcell.StyleDefault.Bold(true) return ss }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/panel.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L44-L47
go
train
// Draw draws the Panel.
func (p *Panel) Draw()
// Draw draws the Panel. func (p *Panel) Draw()
{ p.BoxLayout.SetOrientation(Vertical) p.BoxLayout.Draw() }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/panel.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L50-L56
go
train
// SetTitle sets the Widget to display in the title area.
func (p *Panel) SetTitle(w Widget)
// SetTitle sets the Widget to display in the title area. func (p *Panel) SetTitle(w Widget)
{ if p.title != nil { p.RemoveWidget(p.title) } p.InsertWidget(0, w, 0.0) p.title = w }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/panel.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L60-L70
go
train
// SetMenu sets the Widget to display in the menu area, which is // just below the title.
func (p *Panel) SetMenu(w Widget)
// SetMenu sets the Widget to display in the menu area, which is // just below the title. func (p *Panel) SetMenu(w Widget)
{ index := 0 if p.title != nil { index++ } if p.menu != nil { p.RemoveWidget(p.menu) } p.InsertWidget(index, w, 0.0) p.menu = w }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/panel.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L73-L86
go
train
// SetContent sets the Widget to display in the content area.
func (p *Panel) SetContent(w Widget)
// SetContent sets the Widget to display in the content area. func (p *Panel) SetContent(w Widget)
{ index := 0 if p.title != nil { index++ } if p.menu != nil { index++ } if p.content != nil { p.RemoveWidget(p.content) } p.InsertWidget(index, w, 1.0) p.content = w }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/panel.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/panel.go#L90-L106
go
train
// SetStatus sets the Widget to display in the status area, which is at // the bottom of the panel.
func (p *Panel) SetStatus(w Widget)
// SetStatus sets the Widget to display in the status area, which is at // the bottom of the panel. func (p *Panel) SetStatus(w Widget)
{ index := 0 if p.title != nil { index++ } if p.menu != nil { index++ } if p.content != nil { index++ } if p.status != nil { p.RemoveWidget(p.status) } p.InsertWidget(index, w, 0.0) p.status = w }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L51-L94
go
train
// Draw draws the content.
func (a *CellView) Draw()
// Draw draws the content. func (a *CellView) Draw()
{ port := a.port model := a.model port.Fill(' ', a.style) if a.view == nil { return } if model == nil { return } vw, vh := a.view.Size() for y := 0; y < vh; y++ { for x := 0; x < vw; x++ { a.view.SetContent(x, y, ' ', nil, a.style) } } ex, ey := model.GetBounds() vx, vy := port.Size() if ex < vx { ex = vx } if ey < vy { ey = vy } cx, cy, en, sh := a.model.GetCursor() for y := 0; y < ey; y++ { for x := 0; x < ex; x++ { ch, style, comb, wid := model.GetCell(x, y) if ch == 0 { ch = ' ' style = a.style } if en && x == cx && y == cy && sh { style = style.Reverse(true) } port.SetContent(x, y, ch, comb, style) x += wid - 1 } } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L176-L184
go
train
// MakeCursorVisible ensures that the cursor is visible, panning the ViewPort // as necessary, if the cursor is enabled.
func (a *CellView) MakeCursorVisible()
// MakeCursorVisible ensures that the cursor is visible, panning the ViewPort // as necessary, if the cursor is enabled. func (a *CellView) MakeCursorVisible()
{ if a.model == nil { return } x, y, enabled, _ := a.model.GetCursor() if enabled { a.MakeVisible(x, y) } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L188-L222
go
train
// HandleEvent handles events. In particular, it handles certain key events // to move the cursor or pan the view.
func (a *CellView) HandleEvent(e tcell.Event) bool
// HandleEvent handles events. In particular, it handles certain key events // to move the cursor or pan the view. func (a *CellView) HandleEvent(e tcell.Event) bool
{ if a.model == nil { return false } switch e := e.(type) { case *tcell.EventKey: switch e.Key() { case tcell.KeyUp, tcell.KeyCtrlP: a.keyUp() return true case tcell.KeyDown, tcell.KeyCtrlN: a.keyDown() return true case tcell.KeyRight, tcell.KeyCtrlF: a.keyRight() return true case tcell.KeyLeft, tcell.KeyCtrlB: a.keyLeft() return true case tcell.KeyPgDn: a.keyPgDn() return true case tcell.KeyPgUp: a.keyPgUp() return true case tcell.KeyEnd: a.keyEnd() return true case tcell.KeyHome: a.keyHome() return true } } return false }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L225-L236
go
train
// Size returns the content size, based on the model.
func (a *CellView) Size() (int, int)
// Size returns the content size, based on the model. func (a *CellView) Size() (int, int)
{ // We always return a minimum of two rows, and two columns. w, h := a.model.GetBounds() // Clip to a 2x2 minimum square; we can scroll within that. if w > 2 { w = 2 } if h > 2 { h = 2 } return w, h }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L239-L246
go
train
// SetModel sets the model for this CellView.
func (a *CellView) SetModel(model CellModel)
// SetModel sets the model for this CellView. func (a *CellView) SetModel(model CellModel)
{ w, h := model.GetBounds() model.SetCursor(0, 0) a.model = model a.port.SetContentSize(w, h, true) a.port.ValidateView() a.PostEventWidgetContent(a) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L249-L263
go
train
// SetView sets the View context.
func (a *CellView) SetView(view View)
// SetView sets the View context. func (a *CellView) SetView(view View)
{ port := a.port port.SetView(view) a.view = view if view == nil { return } width, height := view.Size() a.port.Resize(0, 0, width, height) if a.model != nil { w, h := a.model.GetBounds() a.port.SetContentSize(w, h, true) } a.Resize() }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L267-L273
go
train
// Resize is called when the View is resized. It will ensure that the // cursor is visible, if present.
func (a *CellView) Resize()
// Resize is called when the View is resized. It will ensure that the // cursor is visible, if present. func (a *CellView) Resize()
{ // We might want to reflow text width, height := a.view.Size() a.port.Resize(0, 0, width, height) a.port.ValidateView() a.MakeCursorVisible() }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L276-L280
go
train
// SetCursor sets the the cursor position.
func (a *CellView) SetCursor(x, y int)
// SetCursor sets the the cursor position. func (a *CellView) SetCursor(x, y int)
{ a.cursorX = x a.cursorY = y a.model.SetCursor(x, y) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L283-L285
go
train
// SetCursorX sets the the cursor column.
func (a *CellView) SetCursorX(x int)
// SetCursorX sets the the cursor column. func (a *CellView) SetCursorX(x int)
{ a.SetCursor(x, a.cursorY) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L288-L290
go
train
// SetCursorY sets the the cursor row.
func (a *CellView) SetCursorY(y int)
// SetCursorY sets the the cursor row. func (a *CellView) SetCursorY(y int)
{ a.SetCursor(a.cursorX, y) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L294-L296
go
train
// MakeVisible makes the given coordinates visible, if they are not already. // It does this by moving the ViewPort for the CellView.
func (a *CellView) MakeVisible(x, y int)
// MakeVisible makes the given coordinates visible, if they are not already. // It does this by moving the ViewPort for the CellView. func (a *CellView) MakeVisible(x, y int)
{ a.port.MakeVisible(x, y) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/cellarea.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L304-L309
go
train
// Init initializes a new CellView for use.
func (a *CellView) Init()
// Init initializes a new CellView for use. func (a *CellView) Init()
{ a.once.Do(func() { a.port = NewViewPort(nil, 0, 0, 0, 0) a.style = tcell.StyleDefault }) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
encoding/all.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/encoding/all.go#L32-L115
go
train
// Register registers all known encodings. This is a short-cut to // add full character set support to your program. Note that this can // add several megabytes to your program's size, because some of the encodings // are rather large (particularly those from East Asia.)
func Register()
// Register registers all known encodings. This is a short-cut to // add full character set support to your program. Note that this can // add several megabytes to your program's size, because some of the encodings // are rather large (particularly those from East Asia.) func Register()
{ // We supply latin1 and latin5, because Go doesn't tcell.RegisterEncoding("ISO8859-1", encoding.ISO8859_1) tcell.RegisterEncoding("ISO8859-9", encoding.ISO8859_9) tcell.RegisterEncoding("ISO8859-10", charmap.ISO8859_10) tcell.RegisterEncoding("ISO8859-13", charmap.ISO8859_13) tcell.RegisterEncoding("ISO8859-14", charmap.ISO8859_14) tcell.RegisterEncoding("ISO8859-15", charmap.ISO8859_15) tcell.RegisterEncoding("ISO8859-16", charmap.ISO8859_16) tcell.RegisterEncoding("ISO8859-2", charmap.ISO8859_2) tcell.RegisterEncoding("ISO8859-3", charmap.ISO8859_3) tcell.RegisterEncoding("ISO8859-4", charmap.ISO8859_4) tcell.RegisterEncoding("ISO8859-5", charmap.ISO8859_5) tcell.RegisterEncoding("ISO8859-6", charmap.ISO8859_6) tcell.RegisterEncoding("ISO8859-7", charmap.ISO8859_7) tcell.RegisterEncoding("ISO8859-8", charmap.ISO8859_8) tcell.RegisterEncoding("KOI8-R", charmap.KOI8R) tcell.RegisterEncoding("KOI8-U", charmap.KOI8U) // Asian stuff tcell.RegisterEncoding("EUC-JP", japanese.EUCJP) tcell.RegisterEncoding("SHIFT_JIS", japanese.ShiftJIS) tcell.RegisterEncoding("ISO2022JP", japanese.ISO2022JP) tcell.RegisterEncoding("EUC-KR", korean.EUCKR) tcell.RegisterEncoding("GB18030", simplifiedchinese.GB18030) tcell.RegisterEncoding("GB2312", simplifiedchinese.HZGB2312) tcell.RegisterEncoding("GBK", simplifiedchinese.GBK) tcell.RegisterEncoding("Big5", traditionalchinese.Big5) // Common aliaess aliases := map[string]string{ "8859-1": "ISO8859-1", "ISO-8859-1": "ISO8859-1", "8859-13": "ISO8859-13", "ISO-8859-13": "ISO8859-13", "8859-14": "ISO8859-14", "ISO-8859-14": "ISO8859-14", "8859-15": "ISO8859-15", "ISO-8859-15": "ISO8859-15", "8859-16": "ISO8859-16", "ISO-8859-16": "ISO8859-16", "8859-2": "ISO8859-2", "ISO-8859-2": "ISO8859-2", "8859-3": "ISO8859-3", "ISO-8859-3": "ISO8859-3", "8859-4": "ISO8859-4", "ISO-8859-4": "ISO8859-4", "8859-5": "ISO8859-5", "ISO-8859-5": "ISO8859-5", "8859-6": "ISO8859-6", "ISO-8859-6": "ISO8859-6", "8859-7": "ISO8859-7", "ISO-8859-7": "ISO8859-7", "8859-8": "ISO8859-8", "ISO-8859-8": "ISO8859-8", "8859-9": "ISO8859-9", "ISO-8859-9": "ISO8859-9", "SJIS": "Shift_JIS", "EUCJP": "EUC-JP", "2022-JP": "ISO2022JP", "ISO-2022-JP": "ISO2022JP", "EUCKR": "EUC-KR", // ISO646 isn't quite exactly ASCII, but the 1991 IRV // (international reference version) is so. This helps // some older systems that may use "646" for POSIX locales. "646": "US-ASCII", "ISO646": "US-ASCII", // Other names for UTF-8 "UTF8": "UTF-8", } for n, v := range aliases { if enc := tcell.GetEncoding(v); enc != nil { tcell.RegisterEncoding(n, enc) } } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
simulation.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/simulation.go#L26-L32
go
train
// NewSimulationScreen returns a SimulationScreen. Note that // SimulationScreen is also a Screen.
func NewSimulationScreen(charset string) SimulationScreen
// NewSimulationScreen returns a SimulationScreen. Note that // SimulationScreen is also a Screen. func NewSimulationScreen(charset string) SimulationScreen
{ if charset == "" { charset = "UTF-8" } s := &simscreen{charset: charset} return s }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
resize.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/resize.go#L30-L32
go
train
// NewEventResize creates an EventResize with the new updated window size, // which is given in character cells.
func NewEventResize(width, height int) *EventResize
// NewEventResize creates an EventResize with the new updated window size, // which is given in character cells. func NewEventResize(width, height int) *EventResize
{ return &EventResize{t: time.Now(), w: width, h: height} }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L317-L322
go
train
// Start initializes the params buffer with the initial string data. // It also locks the paramsBuffer. The caller must call End() when // finished.
func (pb *paramsBuffer) Start(s string)
// Start initializes the params buffer with the initial string data. // It also locks the paramsBuffer. The caller must call End() when // finished. func (pb *paramsBuffer) Start(s string)
{ pb.lk.Lock() pb.out.Reset() pb.buf.Reset() pb.buf.WriteString(s) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L325-L329
go
train
// End returns the final output from TParam, but it also releases the lock.
func (pb *paramsBuffer) End() string
// End returns the final output from TParam, but it also releases the lock. func (pb *paramsBuffer) End() string
{ s := pb.out.String() pb.lk.Unlock() return s }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L351-L617
go
train
// TParm takes a terminfo parameterized string, such as setaf or cup, and // evaluates the string, and returns the result with the parameter // applied.
func (t *Terminfo) TParm(s string, p ...int) string
// TParm takes a terminfo parameterized string, such as setaf or cup, and // evaluates the string, and returns the result with the parameter // applied. func (t *Terminfo) TParm(s string, p ...int) string
{ var stk stack var a, b string var ai, bi int var ab bool var dvars [26]string var params [9]int pb.Start(s) // make sure we always have 9 parameters -- makes it easier // later to skip checks for i := 0; i < len(params) && i < len(p); i++ { params[i] = p[i] } nest := 0 for { ch, err := pb.NextCh() if err != nil { break } if ch != '%' { pb.PutCh(ch) continue } ch, err = pb.NextCh() if err != nil { // XXX Error break } switch ch { case '%': // quoted % pb.PutCh(ch) case 'i': // increment both parameters (ANSI cup support) params[0]++ params[1]++ case 'c', 's': // NB: these, and 'd' below are special cased for // efficiency. They could be handled by the richer // format support below, less efficiently. a, stk = stk.Pop() pb.PutString(a) case 'd': ai, stk = stk.PopInt() pb.PutString(strconv.Itoa(ai)) case '0', '1', '2', '3', '4', 'x', 'X', 'o', ':': // This is pretty suboptimal, but this is rarely used. // None of the mainstream terminals use any of this, // and it would surprise me if this code is ever // executed outside of test cases. f := "%" if ch == ':' { ch, _ = pb.NextCh() } f += string(ch) for ch == '+' || ch == '-' || ch == '#' || ch == ' ' { ch, _ = pb.NextCh() f += string(ch) } for (ch >= '0' && ch <= '9') || ch == '.' { ch, _ = pb.NextCh() f += string(ch) } switch ch { case 'd', 'x', 'X', 'o': ai, stk = stk.PopInt() pb.PutString(fmt.Sprintf(f, ai)) case 'c', 's': a, stk = stk.Pop() pb.PutString(fmt.Sprintf(f, a)) } case 'p': // push parameter ch, _ = pb.NextCh() ai = int(ch - '1') if ai >= 0 && ai < len(params) { stk = stk.PushInt(params[ai]) } else { stk = stk.PushInt(0) } case 'P': // pop & store variable ch, _ = pb.NextCh() if ch >= 'A' && ch <= 'Z' { svars[int(ch-'A')], stk = stk.Pop() } else if ch >= 'a' && ch <= 'z' { dvars[int(ch-'a')], stk = stk.Pop() } case 'g': // recall & push variable ch, _ = pb.NextCh() if ch >= 'A' && ch <= 'Z' { stk = stk.Push(svars[int(ch-'A')]) } else if ch >= 'a' && ch <= 'z' { stk = stk.Push(dvars[int(ch-'a')]) } case '\'': // push(char) ch, _ = pb.NextCh() pb.NextCh() // must be ' but we don't check stk = stk.Push(string(ch)) case '{': // push(int) ai = 0 ch, _ = pb.NextCh() for ch >= '0' && ch <= '9' { ai *= 10 ai += int(ch - '0') ch, _ = pb.NextCh() } // ch must be '}' but no verification stk = stk.PushInt(ai) case 'l': // push(strlen(pop)) a, stk = stk.Pop() stk = stk.PushInt(len(a)) case '+': bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushInt(ai + bi) case '-': bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushInt(ai - bi) case '*': bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushInt(ai * bi) case '/': bi, stk = stk.PopInt() ai, stk = stk.PopInt() if bi != 0 { stk = stk.PushInt(ai / bi) } else { stk = stk.PushInt(0) } case 'm': // push(pop mod pop) bi, stk = stk.PopInt() ai, stk = stk.PopInt() if bi != 0 { stk = stk.PushInt(ai % bi) } else { stk = stk.PushInt(0) } case '&': // AND bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushInt(ai & bi) case '|': // OR bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushInt(ai | bi) case '^': // XOR bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushInt(ai ^ bi) case '~': // bit complement ai, stk = stk.PopInt() stk = stk.PushInt(ai ^ -1) case '!': // logical NOT ai, stk = stk.PopInt() stk = stk.PushBool(ai != 0) case '=': // numeric compare or string compare b, stk = stk.Pop() a, stk = stk.Pop() stk = stk.PushBool(a == b) case '>': // greater than, numeric bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushBool(ai > bi) case '<': // less than, numeric bi, stk = stk.PopInt() ai, stk = stk.PopInt() stk = stk.PushBool(ai < bi) case '?': // start conditional case 't': ab, stk = stk.PopBool() if ab { // just keep going break } nest = 0 ifloop: // this loop consumes everything until we hit our else, // or the end of the conditional for { ch, err = pb.NextCh() if err != nil { break } if ch != '%' { continue } ch, _ = pb.NextCh() switch ch { case ';': if nest == 0 { break ifloop } nest-- case '?': nest++ case 'e': if nest == 0 { break ifloop } } } case 'e': // if we got here, it means we didn't use the else // in the 't' case above, and we should skip until // the end of the conditional nest = 0 elloop: for { ch, err = pb.NextCh() if err != nil { break } if ch != '%' { continue } ch, _ = pb.NextCh() switch ch { case ';': if nest == 0 { break elloop } nest-- case '?': nest++ } } case ';': // endif } } return pb.End() }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L625-L671
go
train
// TPuts emits the string to the writer, but expands inline padding // indications (of the form $<[delay]> where [delay] is msec) to // a suitable number of padding characters (usually null bytes) based // upon the supplied baud. At high baud rates, more padding characters // will be inserted. All Terminfo based strings should be emitted using // this function.
func (t *Terminfo) TPuts(w io.Writer, s string, baud int)
// TPuts emits the string to the writer, but expands inline padding // indications (of the form $<[delay]> where [delay] is msec) to // a suitable number of padding characters (usually null bytes) based // upon the supplied baud. At high baud rates, more padding characters // will be inserted. All Terminfo based strings should be emitted using // this function. func (t *Terminfo) TPuts(w io.Writer, s string, baud int)
{ for { beg := strings.Index(s, "$<") if beg < 0 { // Most strings don't need padding, which is good news! io.WriteString(w, s) return } io.WriteString(w, s[:beg]) s = s[beg+2:] end := strings.Index(s, ">") if end < 0 { // unterminated.. just emit bytes unadulterated io.WriteString(w, "$<"+s) return } val := s[:end] s = s[end+1:] padus := 0 unit := 1000 dot := false loop: for i := range val { switch val[i] { case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': padus *= 10 padus += int(val[i] - '0') if dot { unit *= 10 } case '.': if !dot { dot = true } else { break loop } default: break loop } } cnt := int(((baud / 8) * padus) / unit) for cnt > 0 { io.WriteString(w, t.PadChar) cnt-- } } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L675-L677
go
train
// TGoto returns a string suitable for addressing the cursor at the given // row and column. The origin 0, 0 is in the upper left corner of the screen.
func (t *Terminfo) TGoto(col, row int) string
// TGoto returns a string suitable for addressing the cursor at the given // row and column. The origin 0, 0 is in the upper left corner of the screen. func (t *Terminfo) TGoto(col, row int) string
{ return t.TParm(t.SetCursor, row, col) }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L681-L702
go
train
// TColor returns a string corresponding to the given foreground and background // colors. Either fg or bg can be set to -1 to elide.
func (t *Terminfo) TColor(fi, bi int) string
// TColor returns a string corresponding to the given foreground and background // colors. Either fg or bg can be set to -1 to elide. func (t *Terminfo) TColor(fi, bi int) string
{ rv := "" // As a special case, we map bright colors to lower versions if the // color table only holds 8. For the remaining 240 colors, the user // is out of luck. Someday we could create a mapping table, but its // not worth it. if t.Colors == 8 { if fi > 7 && fi < 16 { fi -= 8 } if bi > 7 && bi < 16 { bi -= 8 } } if t.Colors > fi && fi >= 0 { rv += t.TParm(t.SetFg, fi) } if t.Colors > bi && bi >= 0 { rv += t.TParm(t.SetBg, bi) } return rv }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L711-L718
go
train
// AddTerminfo can be called to register a new Terminfo entry.
func AddTerminfo(t *Terminfo)
// AddTerminfo can be called to register a new Terminfo entry. func AddTerminfo(t *Terminfo)
{ dblock.Lock() terminfos[t.Name] = t for _, x := range t.Aliases { terminfos[x] = t } dblock.Unlock() }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
terminfo/terminfo.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L768-L923
go
train
// LookupTerminfo attempts to find a definition for the named $TERM. // It first looks in the builtin database, which should cover just about // everyone. If it can't find one there, then it will attempt to read // one from the JSON file located in either $TCELLDB, $HOME/.tcelldb, // or as a database file. // // The database files are named by taking terminal name, hashing it through // sha1, and then a subdirectory of the form database/hash[0:2]/hash[0:8] // (with an optional .gz extension). // // For other local database files, we will look for the database file using // the terminal name, so database/term[0:2]/term[0:8], again with optional // .gz extension.
func LookupTerminfo(name string) (*Terminfo, error)
// LookupTerminfo attempts to find a definition for the named $TERM. // It first looks in the builtin database, which should cover just about // everyone. If it can't find one there, then it will attempt to read // one from the JSON file located in either $TCELLDB, $HOME/.tcelldb, // or as a database file. // // The database files are named by taking terminal name, hashing it through // sha1, and then a subdirectory of the form database/hash[0:2]/hash[0:8] // (with an optional .gz extension). // // For other local database files, we will look for the database file using // the terminal name, so database/term[0:2]/term[0:8], again with optional // .gz extension. func LookupTerminfo(name string) (*Terminfo, error)
{ if name == "" { // else on windows: index out of bounds // on the name[0] reference below return nil, ErrTermNotFound } addtruecolor := false switch os.Getenv("COLORTERM") { case "truecolor", "24bit", "24-bit": addtruecolor = true } dblock.Lock() t := terminfos[name] dblock.Unlock() if t == nil { var files []string letter := fmt.Sprintf("%02x", name[0]) gzfile := path.Join(letter, name+".gz") jsfile := path.Join(letter, name) hash := fmt.Sprintf("%x", sha1.Sum([]byte(name))) gzhfile := path.Join(hash[0:2], hash[0:8]+".gz") jshfile := path.Join(hash[0:2], hash[0:8]) // Build up the search path. Old versions of tcell used a // single database file, whereas the new ones locate them // in JSON (optionally compressed) files. // // The search path for "xterm" (SHA1 sig e2e28a8e...) looks // like this: // // $TCELLDB/78/xterm.gz // $TCELLDB/78/xterm // $TCELLDB // $HOME/.tcelldb/e2/e2e28a8e.gz // $HOME/.tcelldb/e2/e2e28a8e // $HOME/.tcelldb/78/xterm.gz // $HOME/.tcelldb/78/xterm // $HOME/.tcelldb // $GOPATH/terminfo/database/e2/e2e28a8e.gz // $GOPATH/terminfo/database/e2/e2e28a8e // $GOPATH/terminfo/database/78/xterm.gz // $GOPATH/terminfo/database/78/xterm // // Note that the legacy name lookups (78/xterm etc.) are // provided for compatibility. We do not actually deliver // any files with this style of naming, to avoid collisions // on case insensitive filesystems. (*cough* mac *cough*). // If $GOPATH set, honor it, else assume $HOME/go just like // modern golang does. gopath := os.Getenv("GOPATH") if gopath == "" { gopath = path.Join(os.Getenv("HOME"), "go") } if pth := os.Getenv("TCELLDB"); pth != "" { files = append(files, path.Join(pth, gzfile), path.Join(pth, jsfile), pth) } if pth := os.Getenv("HOME"); pth != "" { pth = path.Join(pth, ".tcelldb") files = append(files, path.Join(pth, gzhfile), path.Join(pth, jshfile), path.Join(pth, gzfile), path.Join(pth, jsfile), pth) } for _, pth := range filepath.SplitList(gopath) { pth = path.Join(pth, "src", "github.com", "gdamore", "tcell", "terminfo", "database") files = append(files, path.Join(pth, gzhfile), path.Join(pth, jshfile), path.Join(pth, gzfile), path.Join(pth, jsfile)) } for _, fname := range files { t, _ = loadFromFile(fname, name) if t != nil { break } } if t != nil { if t.Name != name { // Check for a database loop (no infinite // recursion). dblock.Lock() if aliases[name] != "" { dblock.Unlock() return nil, ErrTermNotFound } aliases[name] = t.Name dblock.Unlock() return LookupTerminfo(t.Name) } dblock.Lock() terminfos[name] = t dblock.Unlock() } } // If the name ends in -truecolor, then fabricate an entry // from the corresponding -256color, -color, or bare terminal. if t == nil && strings.HasSuffix(name, "-truecolor") { suffixes := []string{ "-256color", "-88color", "-color", "", } base := name[:len(name)-len("-truecolor")] for _, s := range suffixes { if t, _ = LookupTerminfo(base + s); t != nil { addtruecolor = true break } } } if t == nil { return nil, ErrTermNotFound } switch os.Getenv("TCELL_TRUECOLOR") { case "": case "disable": addtruecolor = false default: addtruecolor = true } // If the user has requested 24-bit color with $COLORTERM, then // amend the value (unless already present). This means we don't // need to have a value present. if addtruecolor && t.SetFgBgRGB == "" && t.SetFgRGB == "" && t.SetBgRGB == "" { // Supply vanilla ISO 8613-6:1994 24-bit color sequences. t.SetFgRGB = "\x1b[38;2;%p1%d;%p2%d;%p3%dm" t.SetBgRGB = "\x1b[48;2;%p1%d;%p2%d;%p3%dm" t.SetFgBgRGB = "\x1b[38;2;%p1%d;%p2%d;%p3%d;" + "48;2;%p4%d;%p5%d;%p6%dm" } return t, nil }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
screen.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/screen.go#L200-L209
go
train
// NewScreen returns a default Screen suitable for the user's terminal // environment.
func NewScreen() (Screen, error)
// NewScreen returns a default Screen suitable for the user's terminal // environment. func NewScreen() (Screen, error)
{ // Windows is happier if we try for a console screen first. if s, _ := NewConsoleScreen(); s != nil { return s, nil } else if s, e := NewTerminfoScreen(); s != nil { return s, nil } else { return nil, e } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/app.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L39-L47
go
train
// initialize initializes the application. It will normally attempt to // allocate a default screen if one is not already established.
func (app *Application) initialize() error
// initialize initializes the application. It will normally attempt to // allocate a default screen if one is not already established. func (app *Application) initialize() error
{ if app.screen == nil { if app.screen, app.err = tcell.NewScreen(); app.err != nil { return app.err } app.screen.SetStyle(app.style) } return nil }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/app.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L51-L57
go
train
// Quit causes the application to shutdown gracefully. It does not wait // for the application to exit, but returns immediately.
func (app *Application) Quit()
// Quit causes the application to shutdown gracefully. It does not wait // for the application to exit, but returns immediately. func (app *Application) Quit()
{ ev := &eventAppQuit{} ev.SetEventNow() if scr := app.screen; scr != nil { go func() { scr.PostEventWait(ev) }() } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/app.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L61-L67
go
train
// Refresh causes the application forcibly redraw everything. Use this // to clear up screen corruption, etc.
func (app *Application) Refresh()
// Refresh causes the application forcibly redraw everything. Use this // to clear up screen corruption, etc. func (app *Application) Refresh()
{ ev := &eventAppRefresh{} ev.SetEventNow() if scr := app.screen; scr != nil { go func() { scr.PostEventWait(ev) }() } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/app.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L71-L77
go
train
// Update asks the application to draw any screen updates that have not // been drawn yet.
func (app *Application) Update()
// Update asks the application to draw any screen updates that have not // been drawn yet. func (app *Application) Update()
{ ev := &eventAppUpdate{} ev.SetEventNow() if scr := app.screen; scr != nil { go func() { scr.PostEventWait(ev) }() } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/app.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L82-L88
go
train
// PostFunc posts a function to be executed in the context of the // application's event loop. Functions that need to update displayed // state, etc. can do this to avoid holding locks.
func (app *Application) PostFunc(fn func())
// PostFunc posts a function to be executed in the context of the // application's event loop. Functions that need to update displayed // state, etc. can do this to avoid holding locks. func (app *Application) PostFunc(fn func())
{ ev := &eventAppFunc{fn: fn} ev.SetEventNow() if scr := app.screen; scr != nil { go func() { scr.PostEventWait(ev) }() } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/app.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L92-L97
go
train
// SetScreen sets the screen to use for the application. This must be // done before the application starts to run or is initialized.
func (app *Application) SetScreen(scr tcell.Screen)
// SetScreen sets the screen to use for the application. This must be // done before the application starts to run or is initialized. func (app *Application) SetScreen(scr tcell.Screen)
{ if app.screen == nil { app.screen = scr app.err = nil } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
views/app.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L101-L106
go
train
// SetStyle sets the default style (background) to be used for Widgets // that have not specified any other style.
func (app *Application) SetStyle(style tcell.Style)
// SetStyle sets the default style (background) to be used for Widgets // that have not specified any other style. func (app *Application) SetStyle(style tcell.Style)
{ app.style = style if app.screen != nil { app.screen.SetStyle(style) } }
gdamore/tcell
dcf1bb30770eb1158b67005e1e472de6d74f055d
mouse.go
https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/mouse.go#L69-L71
go
train
// NewEventMouse is used to create a new mouse event. Applications // shouldn't need to use this; its mostly for screen implementors.
func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse
// NewEventMouse is used to create a new mouse event. Applications // shouldn't need to use this; its mostly for screen implementors. func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse
{ return &EventMouse{t: time.Now(), x: x, y: y, btn: btn, mod: mod} }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/package_rewriter.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/package_rewriter.go#L18-L28
go
train
/* * RewritePackage takes a name (eg: my-package/tools), finds its test files using * Go's build package, and then rewrites them. A ginkgo test suite file will * also be added for this package, and all of its child packages. */
func RewritePackage(packageName string)
/* * RewritePackage takes a name (eg: my-package/tools), finds its test files using * Go's build package, and then rewrites them. A ginkgo test suite file will * also be added for this package, and all of its child packages. */ func RewritePackage(packageName string)
{ pkg, err := packageWithName(packageName) if err != nil { panic(fmt.Sprintf("unexpected error reading package: '%s'\n%s\n", packageName, err.Error())) } for _, filename := range findTestsInPackage(pkg) { rewriteTestsInFile(filename) } return }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/package_rewriter.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/package_rewriter.go#L73-L101
go
train
/* * Shells out to `ginkgo bootstrap` to create a test suite file */
func addGinkgoSuiteForPackage(pkg *build.Package)
/* * Shells out to `ginkgo bootstrap` to create a test suite file */ func addGinkgoSuiteForPackage(pkg *build.Package)
{ originalDir, err := os.Getwd() if err != nil { panic(err) } suite_test_file := filepath.Join(pkg.Dir, pkg.Name+"_suite_test.go") _, err = os.Stat(suite_test_file) if err == nil { return // test file already exists, this should be a no-op } err = os.Chdir(pkg.Dir) if err != nil { panic(err) } output, err := exec.Command("ginkgo", "bootstrap").Output() if err != nil { panic(fmt.Sprintf("error running 'ginkgo bootstrap'.\nstdout: %s\n%s\n", output, err.Error())) } err = os.Chdir(originalDir) if err != nil { panic(err) } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/package_rewriter.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/package_rewriter.go#L106-L112
go
train
/* * Shells out to `go fmt` to format the package */
func goFmtPackage(pkg *build.Package)
/* * Shells out to `go fmt` to format the package */ func goFmtPackage(pkg *build.Package)
{ output, err := exec.Command("go", "fmt", pkg.ImportPath).Output() if err != nil { fmt.Printf("Warning: Error running 'go fmt %s'.\nstdout: %s\n%s\n", pkg.ImportPath, output, err.Error()) } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/package_rewriter.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/package_rewriter.go#L119-L127
go
train
/* * Attempts to return a package with its test files already read. * The ImportMode arg to build.Import lets you specify if you want go to read the * buildable go files inside the package, but it fails if the package has no go files */
func packageWithName(name string) (pkg *build.Package, err error)
/* * Attempts to return a package with its test files already read. * The ImportMode arg to build.Import lets you specify if you want go to read the * buildable go files inside the package, but it fails if the package has no go files */ func packageWithName(name string) (pkg *build.Package, err error)
{ pkg, err = build.Default.Import(name, ".", build.ImportMode(0)) if err == nil { return } pkg, err = build.Default.Import(name, ".", build.ImportMode(1)) return }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
extensions/table/table.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/extensions/table/table.go#L44-L47
go
train
/* DescribeTable describes a table-driven test. For example: DescribeTable("a simple table", func(x int, y int, expected bool) { Ω(x > y).Should(Equal(expected)) }, Entry("x > y", 1, 0, true), Entry("x == y", 0, 0, false), Entry("x < y", 0, 1, false), ) The first argument to `DescribeTable` is a string description. The second argument is a function that will be run for each table entry. Your assertions go here - the function is equivalent to a Ginkgo It. The subsequent arguments must be of type `TableEntry`. We recommend using the `Entry` convenience constructors. The `Entry` constructor takes a string description followed by an arbitrary set of parameters. These parameters are passed into your function. Under the hood, `DescribeTable` simply generates a new Ginkgo `Describe`. Each `Entry` is turned into an `It` within the `Describe`. It's important to understand that the `Describe`s and `It`s are generated at evaluation time (i.e. when Ginkgo constructs the tree of tests and before the tests run). Individual Entries can be focused (with FEntry) or marked pending (with PEntry or XEntry). In addition, the entire table can be focused or marked pending with FDescribeTable and PDescribeTable/XDescribeTable. */
func DescribeTable(description string, itBody interface{}, entries ...TableEntry) bool
/* DescribeTable describes a table-driven test. For example: DescribeTable("a simple table", func(x int, y int, expected bool) { Ω(x > y).Should(Equal(expected)) }, Entry("x > y", 1, 0, true), Entry("x == y", 0, 0, false), Entry("x < y", 0, 1, false), ) The first argument to `DescribeTable` is a string description. The second argument is a function that will be run for each table entry. Your assertions go here - the function is equivalent to a Ginkgo It. The subsequent arguments must be of type `TableEntry`. We recommend using the `Entry` convenience constructors. The `Entry` constructor takes a string description followed by an arbitrary set of parameters. These parameters are passed into your function. Under the hood, `DescribeTable` simply generates a new Ginkgo `Describe`. Each `Entry` is turned into an `It` within the `Describe`. It's important to understand that the `Describe`s and `It`s are generated at evaluation time (i.e. when Ginkgo constructs the tree of tests and before the tests run). Individual Entries can be focused (with FEntry) or marked pending (with PEntry or XEntry). In addition, the entire table can be focused or marked pending with FDescribeTable and PDescribeTable/XDescribeTable. */ func DescribeTable(description string, itBody interface{}, entries ...TableEntry) bool
{ describeTable(description, itBody, entries, false, false) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/run_command.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/run_command.go#L144-L154
go
train
// Moves all generated profiles to specified directory
func (r *SpecRunner) moveCoverprofiles(runners []*testrunner.TestRunner)
// Moves all generated profiles to specified directory func (r *SpecRunner) moveCoverprofiles(runners []*testrunner.TestRunner)
{ for _, runner := range runners { _, filename := filepath.Split(runner.CoverageFile) err := os.Rename(runner.CoverageFile, filepath.Join(r.getOutputDir(), filename)) if err != nil { fmt.Printf("Unable to move coverprofile %s, %v\n", runner.CoverageFile, err) return } } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/run_command.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/run_command.go#L157-L192
go
train
// Combines all generated profiles in the specified directory
func (r *SpecRunner) combineCoverprofiles(runners []*testrunner.TestRunner) error
// Combines all generated profiles in the specified directory func (r *SpecRunner) combineCoverprofiles(runners []*testrunner.TestRunner) error
{ path, _ := filepath.Abs(r.getOutputDir()) if !fileExists(path) { return fmt.Errorf("Unable to create combined profile, outputdir does not exist: %s", r.getOutputDir()) } fmt.Println("path is " + path) combined, err := os.OpenFile(filepath.Join(path, r.getCoverprofile()), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666) if err != nil { fmt.Printf("Unable to create combined profile, %v\n", err) return nil // non-fatal error } for _, runner := range runners { contents, err := ioutil.ReadFile(runner.CoverageFile) if err != nil { fmt.Printf("Unable to read coverage file %s to combine, %v\n", runner.CoverageFile, err) return nil // non-fatal error } _, err = combined.Write(contents) if err != nil { fmt.Printf("Unable to append to coverprofile, %v\n", err) return nil // non-fatal error } } fmt.Println("All profiles combined") return nil }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
extensions/table/table_entry.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/extensions/table/table_entry.go#L58-L60
go
train
/* Entry constructs a TableEntry. The first argument is a required description (this becomes the content of the generated Ginkgo `It`). Subsequent parameters are saved off and sent to the callback passed in to `DescribeTable`. Each Entry ends up generating an individual Ginkgo It. */
func Entry(description string, parameters ...interface{}) TableEntry
/* Entry constructs a TableEntry. The first argument is a required description (this becomes the content of the generated Ginkgo `It`). Subsequent parameters are saved off and sent to the callback passed in to `DescribeTable`. Each Entry ends up generating an individual Ginkgo It. */ func Entry(description string, parameters ...interface{}) TableEntry
{ return TableEntry{description, parameters, false, false} }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
extensions/table/table_entry.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/extensions/table/table_entry.go#L65-L67
go
train
/* You can focus a particular entry with FEntry. This is equivalent to FIt. */
func FEntry(description string, parameters ...interface{}) TableEntry
/* You can focus a particular entry with FEntry. This is equivalent to FIt. */ func FEntry(description string, parameters ...interface{}) TableEntry
{ return TableEntry{description, parameters, false, true} }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
extensions/table/table_entry.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/extensions/table/table_entry.go#L72-L74
go
train
/* You can mark a particular entry as pending with PEntry. This is equivalent to PIt. */
func PEntry(description string, parameters ...interface{}) TableEntry
/* You can mark a particular entry as pending with PEntry. This is equivalent to PIt. */ func PEntry(description string, parameters ...interface{}) TableEntry
{ return TableEntry{description, parameters, true, false} }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
extensions/table/table_entry.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/extensions/table/table_entry.go#L79-L81
go
train
/* You can mark a particular entry as pending with XEntry. This is equivalent to XIt. */
func XEntry(description string, parameters ...interface{}) TableEntry
/* You can mark a particular entry as pending with XEntry. This is equivalent to XIt. */ func XEntry(description string, parameters ...interface{}) TableEntry
{ return TableEntry{description, parameters, true, false} }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/import.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/import.go#L13-L29
go
train
/* * Given the root node of an AST, returns the node containing the * import statements for the file. */
func importsForRootNode(rootNode *ast.File) (imports *ast.GenDecl, err error)
/* * Given the root node of an AST, returns the node containing the * import statements for the file. */ func importsForRootNode(rootNode *ast.File) (imports *ast.GenDecl, err error)
{ for _, declaration := range rootNode.Decls { decl, ok := declaration.(*ast.GenDecl) if !ok || len(decl.Specs) == 0 { continue } _, ok = decl.Specs[0].(*ast.ImportSpec) if ok { imports = decl return } } err = errors.New(fmt.Sprintf("Could not find imports for root node:\n\t%#v\n", rootNode)) return }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/import.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/import.go#L55-L81
go
train
/* * Adds import statements for onsi/ginkgo, if missing */
func addGinkgoImports(rootNode *ast.File)
/* * Adds import statements for onsi/ginkgo, if missing */ func addGinkgoImports(rootNode *ast.File)
{ importDecl, err := importsForRootNode(rootNode) if err != nil { panic(err.Error()) } if len(importDecl.Specs) == 0 { // TODO: might need to create a import decl here panic("unimplemented : expected to find an imports block") } needsGinkgo := true for _, importSpec := range importDecl.Specs { importSpec, ok := importSpec.(*ast.ImportSpec) if !ok { continue } if importSpec.Path.Value == "\"github.com/onsi/ginkgo\"" { needsGinkgo = false } } if needsGinkgo { importDecl.Specs = append(importDecl.Specs, createImport(".", "\"github.com/onsi/ginkgo\"")) } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/import.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/import.go#L86-L91
go
train
/* * convenience function to create an import statement */
func createImport(name, path string) *ast.ImportSpec
/* * convenience function to create an import statement */ func createImport(name, path string) *ast.ImportSpec
{ return &ast.ImportSpec{ Name: &ast.Ident{Name: name}, Path: &ast.BasicLit{Kind: 9, Value: path}, } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
internal/spec/specs.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/internal/spec/specs.go#L77-L91
go
train
// toMatch returns a byte[] to be used by regex matchers. When adding new behaviours to the matching function, // this is the place which we append to.
func (e *Specs) toMatch(description string, i int) []byte
// toMatch returns a byte[] to be used by regex matchers. When adding new behaviours to the matching function, // this is the place which we append to. func (e *Specs) toMatch(description string, i int) []byte
{ if i > len(e.names) { return nil } if e.RegexScansFilePath { return []byte( description + " " + e.names[i] + " " + e.specs[i].subject.CodeLocation().FileName) } else { return []byte( description + " " + e.names[i]) } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
internal/remote/server.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/internal/remote/server.go#L39-L51
go
train
//Create a new server, automatically selecting a port
func NewServer(parallelTotal int) (*Server, error)
//Create a new server, automatically selecting a port func NewServer(parallelTotal int) (*Server, error)
{ listener, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { return nil, err } return &Server{ listener: listener, lock: &sync.Mutex{}, alives: make([]func() bool, parallelTotal), beforeSuiteData: types.RemoteBeforeSuiteData{Data: nil, State: types.RemoteBeforeSuiteStatePending}, parallelTotal: parallelTotal, }, nil }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
internal/remote/server.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/internal/remote/server.go#L54-L74
go
train
//Start the server. You don't need to `go s.Start()`, just `s.Start()`
func (server *Server) Start()
//Start the server. You don't need to `go s.Start()`, just `s.Start()` func (server *Server) Start()
{ httpServer := &http.Server{} mux := http.NewServeMux() httpServer.Handler = mux //streaming endpoints mux.HandleFunc("/SpecSuiteWillBegin", server.specSuiteWillBegin) mux.HandleFunc("/BeforeSuiteDidRun", server.beforeSuiteDidRun) mux.HandleFunc("/AfterSuiteDidRun", server.afterSuiteDidRun) mux.HandleFunc("/SpecWillRun", server.specWillRun) mux.HandleFunc("/SpecDidComplete", server.specDidComplete) mux.HandleFunc("/SpecSuiteDidEnd", server.specSuiteDidEnd) //synchronization endpoints mux.HandleFunc("/BeforeSuiteState", server.handleBeforeSuiteState) mux.HandleFunc("/RemoteAfterSuiteData", server.handleRemoteAfterSuiteData) mux.HandleFunc("/counter", server.handleCounter) mux.HandleFunc("/has-counter", server.handleHasCounter) //for backward compatibility go httpServer.Serve(server.listener) }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
internal/remote/server.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/internal/remote/server.go#L91-L95
go
train
// // Streaming Endpoints // //The server will forward all received messages to Ginkgo reporters registered with `RegisterReporters`
func (server *Server) readAll(request *http.Request) []byte
// // Streaming Endpoints // //The server will forward all received messages to Ginkgo reporters registered with `RegisterReporters` func (server *Server) readAll(request *http.Request) []byte
{ defer request.Body.Close() body, _ := ioutil.ReadAll(request.Body) return body }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
internal/remote/server.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/internal/remote/server.go#L170-L174
go
train
// // Synchronization Endpoints //
func (server *Server) RegisterAlive(node int, alive func() bool)
// // Synchronization Endpoints // func (server *Server) RegisterAlive(node int, alive func() bool)
{ server.lock.Lock() defer server.lock.Unlock() server.alives[node-1] = alive }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/ginkgo_ast_nodes.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/ginkgo_ast_nodes.go#L13-L19
go
train
/* * Creates a func init() node */
func createVarUnderscoreBlock() *ast.ValueSpec
/* * Creates a func init() node */ func createVarUnderscoreBlock() *ast.ValueSpec
{ valueSpec := &ast.ValueSpec{} object := &ast.Object{Kind: 4, Name: "_", Decl: valueSpec, Data: 0} ident := &ast.Ident{Name: "_", Obj: object} valueSpec.Names = append(valueSpec.Names, ident) return valueSpec }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/ginkgo_ast_nodes.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/ginkgo_ast_nodes.go#L24-L33
go
train
/* * Creates a Describe("Testing with ginkgo", func() { }) node */
func createDescribeBlock() *ast.CallExpr
/* * Creates a Describe("Testing with ginkgo", func() { }) node */ func createDescribeBlock() *ast.CallExpr
{ blockStatement := &ast.BlockStmt{List: []ast.Stmt{}} fieldList := &ast.FieldList{} funcType := &ast.FuncType{Params: fieldList} funcLit := &ast.FuncLit{Type: funcType, Body: blockStatement} basicLit := &ast.BasicLit{Kind: 9, Value: "\"Testing with Ginkgo\""} describeIdent := &ast.Ident{Name: "Describe"} return &ast.CallExpr{Fun: describeIdent, Args: []ast.Expr{basicLit, funcLit}} }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo/convert/ginkgo_ast_nodes.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/convert/ginkgo_ast_nodes.go#L48-L66
go
train
/* * Convenience function to return the block statement node for a Describe statement */
func blockStatementFromDescribe(desc *ast.CallExpr) *ast.BlockStmt
/* * Convenience function to return the block statement node for a Describe statement */ func blockStatementFromDescribe(desc *ast.CallExpr) *ast.BlockStmt
{ var funcLit *ast.FuncLit var found = false for _, node := range desc.Args { switch node := node.(type) { case *ast.FuncLit: found = true funcLit = node break } } if !found { panic("Error finding ast.FuncLit inside describe statement. Somebody done goofed.") } return funcLit.Body }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L98-L104
go
train
//Some matcher libraries or legacy codebases require a *testing.T //GinkgoT implements an interface analogous to *testing.T and can be used if //the library in question accepts *testing.T through an interface // // For example, with testify: // assert.Equal(GinkgoT(), 123, 123, "they should be equal") // // Or with gomock: // gomock.NewController(GinkgoT()) // // GinkgoT() takes an optional offset argument that can be used to get the // correct line number associated with the failure.
func GinkgoT(optionalOffset ...int) GinkgoTInterface
//Some matcher libraries or legacy codebases require a *testing.T //GinkgoT implements an interface analogous to *testing.T and can be used if //the library in question accepts *testing.T through an interface // // For example, with testify: // assert.Equal(GinkgoT(), 123, 123, "they should be equal") // // Or with gomock: // gomock.NewController(GinkgoT()) // // GinkgoT() takes an optional offset argument that can be used to get the // correct line number associated with the failure. func GinkgoT(optionalOffset ...int) GinkgoTInterface
{ offset := 3 if len(optionalOffset) > 0 { offset = optionalOffset[0] } return testingtproxy.New(GinkgoWriter, Fail, offset) }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L200-L203
go
train
//RunSpecs is the entry point for the Ginkgo test runner. //You must call this within a Golang testing TestX(t *testing.T) function. // //To bootstrap a test suite you can use the Ginkgo CLI: // // ginkgo bootstrap
func RunSpecs(t GinkgoTestingT, description string) bool
//RunSpecs is the entry point for the Ginkgo test runner. //You must call this within a Golang testing TestX(t *testing.T) function. // //To bootstrap a test suite you can use the Ginkgo CLI: // // ginkgo bootstrap func RunSpecs(t GinkgoTestingT, description string) bool
{ specReporters := []Reporter{buildDefaultReporter()} return RunSpecsWithCustomReporters(t, description, specReporters) }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L207-L210
go
train
//To run your tests with Ginkgo's default reporter and your custom reporter(s), replace //RunSpecs() with this method.
func RunSpecsWithDefaultAndCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool
//To run your tests with Ginkgo's default reporter and your custom reporter(s), replace //RunSpecs() with this method. func RunSpecsWithDefaultAndCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool
{ specReporters = append(specReporters, buildDefaultReporter()) return RunSpecsWithCustomReporters(t, description, specReporters) }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L214-L227
go
train
//To run your tests with your custom reporter(s) (and *not* Ginkgo's default reporter), replace //RunSpecs() with this method. Note that parallel tests will not work correctly without the default reporter
func RunSpecsWithCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool
//To run your tests with your custom reporter(s) (and *not* Ginkgo's default reporter), replace //RunSpecs() with this method. Note that parallel tests will not work correctly without the default reporter func RunSpecsWithCustomReporters(t GinkgoTestingT, description string, specReporters []Reporter) bool
{ writer := GinkgoWriter.(*writer.Writer) writer.SetStream(config.DefaultReporterConfig.Verbose) reporters := make([]reporters.Reporter, len(specReporters)) for i, reporter := range specReporters { reporters[i] = reporter } passed, hasFocusedTests := globalSuite.Run(t, description, reporters, writer, config.GinkgoConfig) if passed && hasFocusedTests && strings.TrimSpace(os.Getenv("GINKGO_EDITOR_INTEGRATION")) == "" { fmt.Println("PASS | FOCUSED") os.Exit(types.GINKGO_FOCUS_EXIT_CODE) } return passed }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L244-L252
go
train
//Skip notifies Ginkgo that the current spec was skipped.
func Skip(message string, callerSkip ...int)
//Skip notifies Ginkgo that the current spec was skipped. func Skip(message string, callerSkip ...int)
{ skip := 0 if len(callerSkip) > 0 { skip = callerSkip[0] } globalFailer.Skip(message, codelocation.New(skip+1)) panic(GINKGO_PANIC) }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L275-L280
go
train
//GinkgoRecover should be deferred at the top of any spawned goroutine that (may) call `Fail` //Since Gomega assertions call fail, you should throw a `defer GinkgoRecover()` at the top of any goroutine that //calls out to Gomega // //Here's why: Ginkgo's `Fail` method records the failure and then panics to prevent //further assertions from running. This panic must be recovered. Ginkgo does this for you //if the panic originates in a Ginkgo node (an It, BeforeEach, etc...) // //Unfortunately, if a panic originates on a goroutine *launched* from one of these nodes there's no //way for Ginkgo to rescue the panic. To do this, you must remember to `defer GinkgoRecover()` at the top of such a goroutine.
func GinkgoRecover()
//GinkgoRecover should be deferred at the top of any spawned goroutine that (may) call `Fail` //Since Gomega assertions call fail, you should throw a `defer GinkgoRecover()` at the top of any goroutine that //calls out to Gomega // //Here's why: Ginkgo's `Fail` method records the failure and then panics to prevent //further assertions from running. This panic must be recovered. Ginkgo does this for you //if the panic originates in a Ginkgo node (an It, BeforeEach, etc...) // //Unfortunately, if a panic originates on a goroutine *launched* from one of these nodes there's no //way for Ginkgo to rescue the panic. To do this, you must remember to `defer GinkgoRecover()` at the top of such a goroutine. func GinkgoRecover()
{ e := recover() if e != nil { globalFailer.Panic(codelocation.New(1), e) } }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L300-L303
go
train
//You can mark the tests within a describe block as pending using PDescribe
func PDescribe(text string, body func()) bool
//You can mark the tests within a describe block as pending using PDescribe func PDescribe(text string, body func()) bool
{ globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L317-L320
go
train
//Context blocks allow you to organize your specs. A Context block can contain any number of //BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks. // //In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally //equivalent. The difference is purely semantic -- you typical Describe the behavior of an object //or method and, within that Describe, outline a number of Contexts and Whens.
func Context(text string, body func()) bool
//Context blocks allow you to organize your specs. A Context block can contain any number of //BeforeEach, AfterEach, JustBeforeEach, It, and Measurement blocks. // //In addition you can nest Describe, Context and When blocks. Describe, Context and When blocks are functionally //equivalent. The difference is purely semantic -- you typical Describe the behavior of an object //or method and, within that Describe, outline a number of Contexts and Whens. func Context(text string, body func()) bool
{ globalSuite.PushContainerNode(text, body, types.FlagTypeNone, codelocation.New(1)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L352-L355
go
train
//You can focus the tests within a describe block using FWhen
func FWhen(text string, body func()) bool
//You can focus the tests within a describe block using FWhen func FWhen(text string, body func()) bool
{ globalSuite.PushContainerNode("when "+text, body, types.FlagTypeFocused, codelocation.New(1)) return true }
onsi/ginkgo
eea6ad008b96acdaa524f5b409513bf062b500ad
ginkgo_dsl.go
https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L374-L377
go
train
//It blocks contain your test code and assertions. You cannot nest any other Ginkgo blocks //within an It block. // //Ginkgo will normally run It blocks synchronously. To perform asynchronous tests, pass a //function that accepts a Done channel. When you do this, you can also provide an optional timeout.
func It(text string, body interface{}, timeout ...float64) bool
//It blocks contain your test code and assertions. You cannot nest any other Ginkgo blocks //within an It block. // //Ginkgo will normally run It blocks synchronously. To perform asynchronous tests, pass a //function that accepts a Done channel. When you do this, you can also provide an optional timeout. func It(text string, body interface{}, timeout ...float64) bool
{ globalSuite.PushItNode(text, body, types.FlagTypeNone, codelocation.New(1), parseTimeout(timeout...)) return true }