_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q174100 | Value | validation | func (c *Client) Value() interface{} {
// if we have not yet performed a look-up, do it so a value is returned
if c.value == nil {
var v interface{}
c = c.Child("", nil, v)
}
if c == nil {
return nil
}
return c.value
} | go | {
"resource": ""
} |
q174101 | Child | validation | func (c *Client) Child(path string, params map[string]string, v interface{}) *Client {
u := c.Url + "/" + path
res, err := c.api.Call("GET", u, c.Auth, nil, params)
if err != nil {
return nil
}
err = json.Unmarshal(res, &v)
if err != nil {
log.Printf("%v\n", err)
return nil
}
ret := &Client{
api: c... | go | {
"resource": ""
} |
q174102 | Push | validation | func (c *Client) Push(value interface{}, params map[string]string) (*Client, error) {
body, err := json.Marshal(value)
if err != nil {
log.Printf("%v\n", err)
return nil, err
}
res, err := c.api.Call("POST", c.Url, c.Auth, body, params)
if err != nil {
return nil, err
}
var r map[string]string
err = js... | go | {
"resource": ""
} |
q174103 | Update | validation | func (c *Client) Update(path string, value interface{}, params map[string]string) error {
body, err := json.Marshal(value)
if err != nil {
log.Printf("%v\n", err)
return err
}
_, err = c.api.Call("PATCH", c.Url+"/"+path, c.Auth, body, params)
// if we've just updated the root node, clear the value so it gets... | go | {
"resource": ""
} |
q174104 | Remove | validation | func (c *Client) Remove(path string, params map[string]string) error {
_, err := c.api.Call("DELETE", c.Url+"/"+path, c.Auth, nil, params)
return err
} | go | {
"resource": ""
} |
q174105 | Rules | validation | func (c *Client) Rules(params map[string]string) (Rules, error) {
res, err := c.api.Call("GET", c.Url+"/.settings/rules", c.Auth, nil, params)
if err != nil {
return nil, err
}
var v Rules
err = json.Unmarshal(res, &v)
if err != nil {
log.Printf("%v\n", err)
return nil, err
}
return v, nil
} | go | {
"resource": ""
} |
q174106 | SetRules | validation | func (c *Client) SetRules(rules *Rules, params map[string]string) error {
body, err := json.Marshal(rules)
if err != nil {
log.Printf("%v\n", err)
return err
}
_, err = c.api.Call("PUT", c.Url+"/.settings/rules", c.Auth, body, params)
return err
} | go | {
"resource": ""
} |
q174107 | Call | validation | func (f *f) Call(method, path, auth string, body []byte, params map[string]string) ([]byte, error) {
if !strings.HasSuffix(path, "/") {
path += "/"
}
path += suffix
qs := url.Values{}
// if the client has an auth, set it as a query string.
// the caller can also override this on a per-call basis
// which wil... | go | {
"resource": ""
} |
q174108 | SetTraceInfo | validation | func (t *trace) SetTraceInfo(traceID uint64, spanID uint64) {
t.trace.SetTraceInfo(traceID, spanID)
} | go | {
"resource": ""
} |
q174109 | Finish | validation | func (t *trace) Finish() {
if t.err {
incrError(t)
}
incr(t)
duration(t)
if t.err {
incrError(t)
}
t.trace.Finish()
} | go | {
"resource": ""
} |
q174110 | ServeMetrics | validation | func ServeMetrics(ctx context.Context, l net.Listener) error {
return http.Serve(l, promhttp.Handler())
} | go | {
"resource": ""
} |
q174111 | DumpMetrics | validation | func DumpMetrics(ctx context.Context, task string) (string, error) {
gatherer := prometheus.DefaultGatherer
mfs, err := gatherer.Gather()
if err != nil {
return "", errors.Wrap(err, "gathering metrics")
}
buf := &bytes.Buffer{}
enc := expfmt.NewEncoder(buf, expfmt.FmtText)
for _, mf := range mfs {
if err :... | go | {
"resource": ""
} |
q174112 | NewEventLog | validation | func NewEventLog(family, title string) xtr.EventLog {
e := &EventLog{
family: family,
title: title,
el: xtr.NewEventLog(family, title),
}
return e
} | go | {
"resource": ""
} |
q174113 | Printf | validation | func (e *EventLog) Printf(format string, a ...interface{}) {
newfmt, newvals := addEvent(e, format, a...)
Log.Printf(newfmt, newvals...)
e.el.Printf(format, a...)
} | go | {
"resource": ""
} |
q174114 | Errorf | validation | func (e *EventLog) Errorf(format string, a ...interface{}) {
Log.Printf("[ERROR] "+format, a...)
e.el.Errorf(format, a...)
} | go | {
"resource": ""
} |
q174115 | SetLogger | validation | func SetLogger(out io.Writer, prefix string, flag int) {
Log = stdlog.New(out, prefix, flag)
} | go | {
"resource": ""
} |
q174116 | ServeHTTP | validation | func (th *timeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
t, _ := trace.NewContext(context.Background(), "webserver", "servehttp")
defer t.Finish()
tm := time.Now().Format(th.format)
// log to the trace
t.LazyPrintf("time %v", tm)
w.Write([]byte("The time is: " + tm))
} | go | {
"resource": ""
} |
q174117 | TitleFromContext | validation | func TitleFromContext(ctx context.Context) string {
id, ok := ctx.Value(TraceIDKey).(string)
if !ok {
return ""
}
return id
} | go | {
"resource": ""
} |
q174118 | NewContext | validation | func NewContext(ctx context.Context, family, title string) (xtr.Trace, context.Context) {
sp := parentOrChildFromContext(ctx, family, title)
return sp, contextWithTrace(ctx, sp)
} | go | {
"resource": ""
} |
q174119 | New | validation | func New(apikey string) *Client {
endpoint := Endpoint{URL: EndpointURL}
return &Client{apikey, http.DefaultClient, endpoint}
} | go | {
"resource": ""
} |
q174120 | NewWithClient | validation | func NewWithClient(apikey string, client *http.Client) *Client {
endpoint := Endpoint{URL: EndpointURL}
return &Client{apikey, client, endpoint}
} | go | {
"resource": ""
} |
q174121 | Devices | validation | func (c *Client) Devices() ([]*Device, error) {
req := c.buildRequest("/devices", nil)
resp, err := c.Client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
var errjson errorResponse
dec := json.NewDecoder(resp.Body)
err = dec.Decode(&errjson)
if e... | go | {
"resource": ""
} |
q174122 | Device | validation | func (c *Client) Device(nickname string) (*Device, error) {
devices, err := c.Devices()
if err != nil {
return nil, err
}
for i := range devices {
if devices[i].Nickname == nickname {
devices[i].Client = c
return devices[i], nil
}
}
return nil, ErrDeviceNotFound
} | go | {
"resource": ""
} |
q174123 | PushNote | validation | func (d *Device) PushNote(title, body string) error {
return d.Client.PushNote(d.Iden, title, body)
} | go | {
"resource": ""
} |
q174124 | PushLink | validation | func (d *Device) PushLink(title, u, body string) error {
return d.Client.PushLink(d.Iden, title, u, body)
} | go | {
"resource": ""
} |
q174125 | PushSMS | validation | func (d *Device) PushSMS(deviceIden, phoneNumber, message string) error {
return d.Client.PushSMS(d.Iden, deviceIden, phoneNumber, message)
} | go | {
"resource": ""
} |
q174126 | Me | validation | func (c *Client) Me() (*User, error) {
req := c.buildRequest("/users/me", nil)
resp, err := c.Client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
var errjson errorResponse
dec := json.NewDecoder(resp.Body)
err = dec.Decode(&errjson)
if err == ni... | go | {
"resource": ""
} |
q174127 | Push | validation | func (c *Client) Push(endPoint string, data interface{}) error {
req := c.buildRequest(endPoint, data)
resp, err := c.Client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
var errResponse errorResponse
dec := json.NewDecoder(resp.Body)
err = dec.Decode(... | go | {
"resource": ""
} |
q174128 | PushNote | validation | func (c *Client) PushNote(iden string, title, body string) error {
data := Note{
Iden: iden,
Type: "note",
Title: title,
Body: body,
}
return c.Push("/pushes", data)
} | go | {
"resource": ""
} |
q174129 | PushNoteToChannel | validation | func (c *Client) PushNoteToChannel(tag string, title, body string) error {
data := Note{
Tag: tag,
Type: "note",
Title: title,
Body: body,
}
return c.Push("/pushes", data)
} | go | {
"resource": ""
} |
q174130 | PushLink | validation | func (c *Client) PushLink(iden, title, u, body string) error {
data := Link{
Iden: iden,
Type: "link",
Title: title,
URL: u,
Body: body,
}
return c.Push("/pushes", data)
} | go | {
"resource": ""
} |
q174131 | PushLinkToChannel | validation | func (c *Client) PushLinkToChannel(tag, title, u, body string) error {
data := Link{
Tag: tag,
Type: "link",
Title: title,
URL: u,
Body: body,
}
return c.Push("/pushes", data)
} | go | {
"resource": ""
} |
q174132 | PushSMS | validation | func (c *Client) PushSMS(userIden, deviceIden, phoneNumber, message string) error {
data := Ephemeral{
Type: "push",
Push: EphemeralPush{
Type: "messaging_extension_reply",
PackageName: "com.pushbullet.android",
SourceUserIden: userIden,
TargetDeviceIden: deviceIden,
ConversationI... | go | {
"resource": ""
} |
q174133 | Subscription | validation | func (c *Client) Subscription(tag string) (*Subscription, error) {
subs, err := c.Subscriptions()
if err != nil {
return nil, err
}
for i := range subs {
if subs[i].Channel.Tag == tag {
subs[i].Client = c
return subs[i], nil
}
}
return nil, ErrDeviceNotFound
} | go | {
"resource": ""
} |
q174134 | PushNote | validation | func (s *Subscription) PushNote(title, body string) error {
return s.Client.PushNoteToChannel(s.Channel.Tag, title, body)
} | go | {
"resource": ""
} |
q174135 | PushLink | validation | func (s *Subscription) PushLink(title, u, body string) error {
return s.Client.PushLinkToChannel(s.Channel.Tag, title, u, body)
} | go | {
"resource": ""
} |
q174136 | NewCachedLoader | validation | func NewCachedLoader(namespace string, consulAddr string) (config.Loader, error) {
config := api.DefaultConfig()
config.Address = consulAddr
consul, err := api.NewClient(config)
if err != nil {
return nil, fmt.Errorf("Could not connect to consul: %v", err)
}
return &cachedLoader{namespace: namespace, consulKV:... | go | {
"resource": ""
} |
q174137 | Import | validation | func (c *cachedLoader) Import(data []byte) error {
conf := make(map[string]interface{})
err := json.Unmarshal(data, &conf)
if err != nil {
return fmt.Errorf("Unable to parse json data: %v", err)
}
kvMap, err := c.compileKeyValues(conf, c.namespace)
if err != nil {
return fmt.Errorf("Unable to complie KVs: %v"... | go | {
"resource": ""
} |
q174138 | Initialize | validation | func (c *cachedLoader) Initialize() error {
pairs, _, err := c.consulKV.List(c.namespace, nil)
if err != nil {
return fmt.Errorf("Could not pull config from consul: %v", err)
}
//write lock the cache incase init is called more than once
c.cacheLock.Lock()
defer c.cacheLock.Unlock()
c.cache = make(map[string]... | go | {
"resource": ""
} |
q174139 | Get | validation | func (c *cachedLoader) Get(key string) ([]byte, error) {
c.cacheLock.RLock()
defer c.cacheLock.RUnlock()
compiledKey := c.namespace + divider + key
if ret, ok := c.cache[compiledKey]; ok {
return ret, nil
}
return nil, fmt.Errorf("Could not find value for key: %s", compiledKey)
} | go | {
"resource": ""
} |
q174140 | MustGetString | validation | func (c *cachedLoader) MustGetString(key string) string {
b, err := c.Get(key)
if err != nil {
panic(fmt.Sprintf("Could not fetch config (%s) %v", key, err))
}
var s string
err = json.Unmarshal(b, &s)
if err != nil {
panic(fmt.Sprintf("Could not unmarshal config (%s) %v", key, err))
}
return s
} | go | {
"resource": ""
} |
q174141 | MustGetBool | validation | func (c *cachedLoader) MustGetBool(key string) bool {
b, err := c.Get(key)
if err != nil {
panic(fmt.Sprintf("Could not fetch config (%s) %v", key, err))
}
var ret bool
err = json.Unmarshal(b, &ret)
if err != nil {
panic(fmt.Sprintf("Could not unmarshal config (%s) %v", key, err))
}
return ret
} | go | {
"resource": ""
} |
q174142 | MustGetInt | validation | func (c *cachedLoader) MustGetInt(key string) int {
b, err := c.Get(key)
if err != nil {
panic(fmt.Sprintf("Could not fetch config (%s) %v", key, err))
}
var ret int
err = json.Unmarshal(b, &ret)
if err != nil {
panic(fmt.Sprintf("Could not unmarshal config (%s) %v", key, err))
}
return ret
} | go | {
"resource": ""
} |
q174143 | MustGetDuration | validation | func (c *cachedLoader) MustGetDuration(key string) time.Duration {
s := c.MustGetString(key)
ret, err := time.ParseDuration(s)
if err != nil {
panic(fmt.Sprintf("Could not parse config (%s) into a duration: %v", key, err))
}
return ret
} | go | {
"resource": ""
} |
q174144 | NewRandomDNSBalancer | validation | func NewRandomDNSBalancer(environment string, consulAddr string, cacheTTL time.Duration) (balancer.DNS, error) {
config := api.DefaultConfig()
config.Address = consulAddr
consul, err := api.NewClient(config)
if err != nil {
return nil, fmt.Errorf("Could not connect to consul: %v", err)
}
r := randomBalancer{}
... | go | {
"resource": ""
} |
q174145 | writeServiceToCache | validation | func (r *randomBalancer) writeServiceToCache(serviceName string) ([]*balancer.ServiceLocation, error) {
//acquire a write lock
r.cacheLock.Lock()
defer r.cacheLock.Unlock()
//check the cache again in case we've fetched since the last check
//(our lock could have been waiting for another call to this function)
if... | go | {
"resource": ""
} |
q174146 | StringToLabels | validation | func StringToLabels(s string) *mesos.Labels {
labels := &mesos.Labels{Labels: make([]*mesos.Label, 0)}
if s == "" {
return labels
}
pairs := strings.Split(s, ";")
for _, pair := range pairs {
kv := strings.Split(pair, "=")
key, value := kv[0], kv[1]
label := &mesos.Label{Key: proto.String(key), Value: prot... | go | {
"resource": ""
} |
q174147 | SetClockSequence | validation | func SetClockSequence(seq int) {
if seq == -1 {
var b [2]byte
randomBits(b[:]) // clock sequence
seq = int(b[0])<<8 | int(b[1])
}
old_seq := clock_seq
clock_seq = uint16(seq&0x3fff) | 0x8000 // Set our variant
if old_seq != clock_seq {
lasttime = 0
}
} | go | {
"resource": ""
} |
q174148 | Trace | validation | func (dl *DefaultLogger) Trace(message string, params ...interface{}) {
dl.logger.Tracef(fmt.Sprintf("%s %s", caller(), message), params...)
} | go | {
"resource": ""
} |
q174149 | Debug | validation | func (dl *DefaultLogger) Debug(message string, params ...interface{}) {
dl.logger.Debugf(fmt.Sprintf("%s %s", caller(), message), params...)
} | go | {
"resource": ""
} |
q174150 | Info | validation | func (dl *DefaultLogger) Info(message string, params ...interface{}) {
dl.logger.Infof(fmt.Sprintf("%s %s", caller(), message), params...)
} | go | {
"resource": ""
} |
q174151 | Warn | validation | func (dl *DefaultLogger) Warn(message string, params ...interface{}) {
dl.logger.Warnf(fmt.Sprintf("%s %s", caller(), message), params...)
} | go | {
"resource": ""
} |
q174152 | Error | validation | func (dl *DefaultLogger) Error(message string, params ...interface{}) {
dl.logger.Errorf(fmt.Sprintf("%s %s", caller(), message), params...)
} | go | {
"resource": ""
} |
q174153 | Critical | validation | func (dl *DefaultLogger) Critical(message string, params ...interface{}) {
dl.logger.Criticalf(fmt.Sprintf("%s %s", caller(), message), params...)
} | go | {
"resource": ""
} |
q174154 | SendPaste | validation | func (api * API) SendPaste(paste Paste) (string, error) {
if paste.UserKey == "" && paste.Privacy == "2" {
return "", PrivacyModError
}
values := url.Values{}
values.Set("api_dev_key", api.APIKey)
values.Set("api_user_key", paste.UserKey)
values.Set("api_option", "paste")
values.Set("api_paste_code", paste.Tex... | go | {
"resource": ""
} |
q174155 | GetPasteTextById | validation | func (api * API) GetPasteTextById(paste_id string) (string, error) {
response, err := http.Get("http://pastebin.com/raw.php?i=" + paste_id)
defer response.Body.Close()
if err != nil {
return "", err
}
if response.StatusCode != 200 {
return "", PasteGetError
}
buf := bytes.Buffer{}
_, err = buf.ReadFrom(resp... | go | {
"resource": ""
} |
q174156 | ExecAndWait | validation | func (e *execStreamer) ExecAndWait() error {
cmd, err := e.StartExec()
if err != nil {
return err
}
e.stdOutAndErrWaitGroup.Wait()
err = cmd.Wait()
if err != nil {
return err
}
return nil
} | go | {
"resource": ""
} |
q174157 | ExecutorName | validation | func (e *execStreamerBuilder) ExecutorName(executorName string) ExecStreamerBuilder {
e.d.ExecutorName = executorName
return e
} | go | {
"resource": ""
} |
q174158 | Exe | validation | func (e *execStreamerBuilder) Exe(exe string) ExecStreamerBuilder {
e.d.Exe = exe
return e
} | go | {
"resource": ""
} |
q174159 | Args | validation | func (e *execStreamerBuilder) Args(args ...string) ExecStreamerBuilder {
e.d.Args = args
return e
} | go | {
"resource": ""
} |
q174160 | Dir | validation | func (e *execStreamerBuilder) Dir(dir string) ExecStreamerBuilder {
e.d.Dir = dir
return e
} | go | {
"resource": ""
} |
q174161 | Env | validation | func (e *execStreamerBuilder) Env(env ...string) ExecStreamerBuilder {
e.d.Env = env
return e
} | go | {
"resource": ""
} |
q174162 | Writers | validation | func (e *execStreamerBuilder) Writers(writers io.Writer) ExecStreamerBuilder {
e.d.StdoutWriter = writers
e.d.StderrWriter = writers
return e
} | go | {
"resource": ""
} |
q174163 | StdoutWriter | validation | func (e *execStreamerBuilder) StdoutWriter(writer io.Writer) ExecStreamerBuilder {
e.d.StdoutWriter = writer
return e
} | go | {
"resource": ""
} |
q174164 | StdoutPrefix | validation | func (e *execStreamerBuilder) StdoutPrefix(prefix string) ExecStreamerBuilder {
e.d.StdoutPrefix = prefix
return e
} | go | {
"resource": ""
} |
q174165 | StderrWriter | validation | func (e *execStreamerBuilder) StderrWriter(writer io.Writer) ExecStreamerBuilder {
e.d.StderrWriter = writer
return e
} | go | {
"resource": ""
} |
q174166 | StderrPrefix | validation | func (e *execStreamerBuilder) StderrPrefix(prefix string) ExecStreamerBuilder {
e.d.StderrPrefix = prefix
return e
} | go | {
"resource": ""
} |
q174167 | Build | validation | func (e *execStreamerBuilder) Build() (ExecStreamer, error) {
if e.d.ExecutorName == "" {
return nil, errors.New("ExecStreamerBuilder requires ExecutorName to be non-empty")
}
if e.d.Exe == "" {
return nil, errors.New("ExecStreamerBuilder requires Exe to be non-empty")
}
if e.d.StdoutWriter == nil {
e.d.Stdo... | go | {
"resource": ""
} |
q174168 | MakeWidget | validation | func MakeWidget(w *Window, x, y int) Widget {
return Widget{
w: w,
x: x,
y: y,
}
} | go | {
"resource": ""
} |
q174169 | SetText | validation | func (l *Label) SetText(format string, args ...interface{}) {
l.text = fmt.Sprintf(format, args...)
} | go | {
"resource": ""
} |
q174170 | AddLabel | validation | func (w *Window) AddLabel(x, y int, format string, args ...interface{}) *Label {
// we can ignore error for builtins
l, _ := w.AddWidget(WidgetLabel, x, y)
label := l.(*Label)
label.Resize()
label.SetAttributes(defaultAttributes())
label.SetText(format, args...)
return label
} | go | {
"resource": ""
} |
q174171 | printf | validation | func (w *Window) printf(x, y int, a Attributes, format string,
args ...interface{}) {
out := fmt.Sprintf(format, args...)
xx := 0
c := Cell{}
c.Fg = a.Fg
c.Bg = a.Bg
mx := w.x - x
var rw int
for i := 0; i < len(out); i += rw {
if x+xx+1 > mx {
break
}
v, width := utf8.DecodeRuneInString(out[i:])
if... | go | {
"resource": ""
} |
q174172 | setCell | validation | func (w *Window) setCell(x, y int, c Cell) {
c.dirty = true
pos := x + (y * w.x)
if pos < len(w.backingStore) {
w.backingStore[pos] = c
}
} | go | {
"resource": ""
} |
q174173 | resize | validation | func (w *Window) resize(x, y int) {
w.x = x
w.y = y
w.backingStore = make([]Cell, x*y)
// iterate over widgets
for _, widget := range w.widgets {
widget.Resize()
}
} | go | {
"resource": ""
} |
q174174 | render | validation | func (w *Window) render() {
w.mgr.Render(w)
// iterate over widgets
for _, widget := range w.widgets {
widget.Render()
}
// focus on a widget
w.focusWidget()
} | go | {
"resource": ""
} |
q174175 | focusWidget | validation | func (w *Window) focusWidget() {
setCursor(-1, -1) // hide
if w.focus < 0 {
for i, widget := range w.widgets {
if widget.CanFocus() {
w.focus = i
widget.Focus()
return
}
}
// nothing to do
return
}
// make sure we are in bounds
if w.focus > len(w.widgets) {
// this really should not ha... | go | {
"resource": ""
} |
q174176 | focusPrevious | validation | func (w *Window) focusPrevious() {
// it is ok to be negative since that'll focus on the first widget
w.focus--
if w.focus < 0 {
w.focusWidget()
return
}
// find previous widget
for i := w.focus; i > 0; i-- {
widget := w.widgets[i]
if !widget.CanFocus() {
continue
}
setCursor(-1, -1) // hide
w.f... | go | {
"resource": ""
} |
q174177 | keyHandler | validation | func (w *Window) keyHandler(ev termbox.Event) (bool, Windower, Widgeter) {
if w.focus < 0 || w.focus > len(w.widgets) {
return false, w.mgr, nil // not used
}
return w.widgets[w.focus].KeyHandler(ev), w.mgr, w.widgets[w.focus]
} | go | {
"resource": ""
} |
q174178 | Color | validation | func Color(at, fg, bg int) (string, error) {
var a, f, b string
// can't be all NA
if at == AttrNA && fg == AttrNA && bg == AttrNA {
return "", ErrInvalidColor
}
switch at {
case AttrNA:
break
case AttrBold, AttrUnderline, AttrReverse, AttrReset:
a = fmt.Sprintf("%v;", at)
default:
return "", ErrInval... | go | {
"resource": ""
} |
q174179 | EscapedLen | validation | func EscapedLen(s string) int {
if len(s) == 0 {
return 0
}
var rw, total int
for i := 0; i < len(s); i += rw {
v, width := utf8.DecodeRuneInString(s[i:])
if v == '\x1b' {
_, skip, err := DecodeColor(s[i:])
if err == nil {
rw = skip
total += skip
continue
}
}
rw = width
}
return ... | go | {
"resource": ""
} |
q174180 | Unescape | validation | func Unescape(s string) string {
if len(s) == 0 {
return ""
}
var ret string
var rw int
for i := 0; i < len(s); i += rw {
v, width := utf8.DecodeRuneInString(s[i:])
if v == '\x1b' {
_, skip, err := DecodeColor(s[i:])
if err == nil {
rw = skip
continue
}
}
ret += string(v)
rw = width
... | go | {
"resource": ""
} |
q174181 | init | validation | func init() {
work = make(chan func(), 32)
keyC = make(chan Key, 1024)
windows = make(map[int]*Window)
windower2window = make(map[Windower]*Window)
// setup render queue
// we do this song and dance in order to be able to deal with slow
// connections where rendering could take a long time
execute := make(chan... | go | {
"resource": ""
} |
q174182 | initKeyHandler | validation | func initKeyHandler() {
for {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
e := ev
Queue(func() {
var (
widget Widgeter
window Windower
)
if focus != nil {
var used bool
used, window, widget = focus.keyHandler(e)
if used {
flush()
return
... | go | {
"resource": ""
} |
q174183 | Init | validation | func Init() error {
rawMtx.Lock()
defer rawMtx.Unlock()
if termRaw {
return ErrAlreadyInitialized
}
// switch mode
err := termbox.Init()
if err != nil {
return err
}
bg = termbox.ColorDefault
fg = termbox.ColorDefault
termbox.HideCursor()
termbox.SetInputMode(termbox.InputAlt) // this may need to bec... | go | {
"resource": ""
} |
q174184 | Deinit | validation | func Deinit() {
wait := make(chan interface{})
Queue(func() {
termbox.Close()
focus = nil
prevFocus = nil
windows = make(map[int]*Window) // toss all windows
rawMtx.Lock()
termRaw = false
rawMtx.Unlock()
wait <- true
})
<-wait
} | go | {
"resource": ""
} |
q174185 | NewWindow | validation | func NewWindow(manager Windower) *Window {
wc := make(chan *Window)
Queue(func() {
w := &Window{
id: lastWindowID,
mgr: manager,
x: maxX,
y: maxY,
focus: -1, // no widget focused
backingStore: make([]Cell, maxX*maxY),
widgets: make([]Widgeter... | go | {
"resource": ""
} |
q174186 | flush | validation | func flush() {
if focus == nil {
return
}
for y := 0; y < focus.y; y++ {
for x := 0; x < focus.x; x++ {
c := focus.getCell(x, y)
if c == nil {
// out of range, should not happen
continue
}
if !c.dirty {
// skip unchanged cells
continue
}
c.dirty = false
// this shall be the ... | go | {
"resource": ""
} |
q174187 | focusWindow | validation | func focusWindow(w *Window) {
if w == nil {
return
}
_, found := windows[w.id]
if !found {
return
}
if focus == w {
return
}
prevFocus = focus
focus = w
resizeAndRender(w)
} | go | {
"resource": ""
} |
q174188 | resizeAndRender | validation | func resizeAndRender(w *Window) {
// render window
if w != nil {
_ = termbox.Clear(bg, bg)
maxX, maxY = termbox.Size()
w.resize(maxX, maxY)
w.render()
// display all the things
flush()
}
} | go | {
"resource": ""
} |
q174189 | Panic | validation | func Panic(format string, args ...interface{}) {
termbox.Close()
msg := fmt.Sprintf(format, args...)
panic(msg)
} | go | {
"resource": ""
} |
q174190 | Exit | validation | func Exit(format string, args ...interface{}) {
termbox.Close()
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
} | go | {
"resource": ""
} |
q174191 | AddList | validation | func (w *Window) AddList(x, y, width, height int) *List {
// we can ignore error for builtins
l, _ := w.AddWidget(WidgetList, x, y)
list := l.(*List)
list.width = width
list.height = height
list.Resize()
list.SetAttributes(defaultAttributes())
list.content = make([]string, 0, 1000)
return list
} | go | {
"resource": ""
} |
q174192 | Append | validation | func (l *List) Append(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
l.content = append(l.content, s)
// adjust at if we are not in a paging operation
if l.paging {
return
}
l.at = len(l.content) - l.trueH
if l.at < 0 {
l.at = 0
}
} | go | {
"resource": ""
} |
q174193 | Focus | validation | func (e *Edit) Focus() {
if e.cx == -1 || e.cy == -1 {
// || is deliberate to handle "just in case"
e.cx = e.trueX
e.cy = e.trueY
e.at = 0
}
setCursor(e.cx, e.cy)
} | go | {
"resource": ""
} |
q174194 | SetText | validation | func (e *Edit) SetText(s *string, end bool) {
e.target = s
e.display = []rune(*s)
e.at = 0
// send synthesized key to position cursor and text
ev := termbox.Event{}
if end {
ev.Key = termbox.KeyCtrlE
} else {
ev.Key = termbox.KeyCtrlA
}
e.KeyHandler(ev)
} | go | {
"resource": ""
} |
q174195 | AddEdit | validation | func (w *Window) AddEdit(x, y, width int, target *string) *Edit {
// we can ignore error for builtins
e, _ := w.AddWidget(WidgetEdit, x, y)
edit := e.(*Edit)
edit.width = width
// save current sizes to detect actual window resizes
edit.prevX = w.x
edit.prevY = w.y
edit.Resize()
// cursor
edit.cx = -1
edit... | go | {
"resource": ""
} |
q174196 | makeAuthorizationHeaders | validation | func (s *Session) makeAuthorizationHeaders() (string, *Error) {
if s.Username == "" {
return "", NewBambouError("Invalid Credentials", "No username given")
}
if s.root == nil {
return "", NewBambouError("Invalid Credentials", "No root user set")
}
key := s.root.APIKey()
if s.Password == "" && key == "" {
... | go | {
"resource": ""
} |
q174197 | Start | validation | func (s *Session) Start() *Error {
currentSession = s
berr := s.FetchEntity(s.root)
if berr != nil {
return berr
}
return nil
} | go | {
"resource": ""
} |
q174198 | FetchEntity | validation | func (s *Session) FetchEntity(object Identifiable) *Error {
url, berr := s.getPersonalURL(object)
if berr != nil {
return berr
}
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return NewBambouError("HTTP transaction error", err.Error())
}
response, berr := s.send(request, nil)
if berr !... | go | {
"resource": ""
} |
q174199 | SaveEntity | validation | func (s *Session) SaveEntity(object Identifiable) *Error {
url, berr := s.getPersonalURL(object)
if berr != nil {
return berr
}
buffer := &bytes.Buffer{}
if err := json.NewEncoder(buffer).Encode(object); err != nil {
return NewBambouError("JSON error", err.Error())
}
url = url + "?responseChoice=1"
reque... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.