about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--docs/api.md68
-rw-r--r--example/src/main.c4
2 files changed, 27 insertions, 45 deletions
diff --git a/docs/api.md b/docs/api.md
index a1a58e8..4a1a80b 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -1,49 +1,31 @@
 # uv_link_t
 
-## Types
-
-### uv_link_t
+## uv_link_t
 
 The base unit of all APIs. Pointer to this structure is what needs to be passed
 to the most of the methods.
 
-### uv_link_methods_t
-
-TODO(indutny)
-
-### uv_link_source_t
-
-TODO(indutny)
-
-### uv_link_observer_t
-
-TODO(indutny)
-
-## Methods
-
-### uv_link_t
-
-#### int uv_link_init(...)
-#### void uv_link_close(...)
-#### int uv_link_chain(...)
-#### int uv_link_unchain(...)
-#### void uv_link_propagate_alloc_cb(...)
-#### void uv_link_propagate_read_cb(...)
-#### int uv_link_propagate_write(...)
-#### int uv_link_propagate_shutdown(...)
-#### void uv_link_propagate_close(...)
-#### int uv_link_read_start(...)
-#### int uv_link_read_stop(...)
-#### int uv_link_write(...)
-#### int uv_link_try_write(...)
-#### int uv_link_shutdown(...)
-
-### uv_link_source_t
-
-#### int uv_link_source_init(...)
-#### int uv_link_observer_init(...)
-
-### uv_link_observer_t
-
-#### int uv_link_observer_init(...)
-#### .observer_read_cb
+### int uv_link_init(...)
+### void uv_link_close(...)
+### int uv_link_chain(...)
+### int uv_link_unchain(...)
+### void uv_link_propagate_alloc_cb(...)
+### void uv_link_propagate_read_cb(...)
+### int uv_link_propagate_write(...)
+### int uv_link_propagate_shutdown(...)
+### void uv_link_propagate_close(...)
+### int uv_link_read_start(...)
+### int uv_link_read_stop(...)
+### int uv_link_write(...)
+### int uv_link_try_write(...)
+### int uv_link_shutdown(...)
+
+## uv_link_source_t
+
+### int uv_link_source_init(...)
+### int uv_link_observer_init(...)
+
+## uv_link_observer_t
+
+### int uv_link_observer_init(...)
+### .observer_read_cb
diff --git a/example/src/main.c b/example/src/main.c
index 215a35a..981c414 100644
--- a/example/src/main.c
+++ b/example/src/main.c
@@ -38,7 +38,7 @@ static void read_cb(uv_link_observer_t* observer,
 
   if (nread < 0) {
     fprintf(stderr, "error or close\n");
-    uv_link_close(&observer->link, close_cb);
+    uv_link_close((uv_link_t*) observer, close_cb);
     return;
   }
 
@@ -60,7 +60,7 @@ static void connection_cb(uv_stream_t* s, int status) {
   CHECK(uv_link_observer_init(&client->observer));
   CHECK(uv_link_chain(&client->middle, (uv_link_t*) &client->observer));
 
-  client->observer.read_cb = read_cb;
+  client->observer.observer_read_cb = read_cb;
   client->observer.data = client;
 
   CHECK(uv_link_read_start((uv_link_t*) &client->observer));
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package commands

type cmdHistory struct {
	// rolling buffer of prior commands
	//
	// most recent command is at the end of the list,
	// least recent is index 0
	cmdList []string

	// current placement in list
	current int
}

// number of commands to keep in history
const cmdLimit = 1000

// CmdHistory is the history of executed commands
var CmdHistory = cmdHistory{}

func (h *cmdHistory) Add(cmd string) {
	// if we're at cap, cut off the first element
	if len(h.cmdList) >= cmdLimit {
		h.cmdList = h.cmdList[1:]
	}

	h.cmdList = append(h.cmdList, cmd)

	// whenever we add a new command, reset the current
	// pointer to the "beginning" of the list
	h.Reset()
}

// Prev returns the previous command in history.
// Since the list is reverse-order, this will return elements
// increasingly towards index 0.
func (h *cmdHistory) Prev() string {
	if h.current <= 0 || len(h.cmdList) == 0 {
		h.current = -1
		return "(Already at beginning)"
	}
	h.current--

	return h.cmdList[h.current]
}

// Next returns the next command in history.
// Since the list is reverse-order, this will return elements
// increasingly towards index len(cmdList).
func (h *cmdHistory) Next() string {
	if h.current >= len(h.cmdList)-1 || len(h.cmdList) == 0 {
		h.current = len(h.cmdList)
		return "(Already at end)"
	}
	h.current++

	return h.cmdList[h.current]
}

// Reset the current pointer to the beginning of history.
func (h *cmdHistory) Reset() {
	h.current = len(h.cmdList)
}