Преглед на файлове

Add __width, __height internal vars. Fix issue #70

git-svn-id: https://klish.googlecode.com/svn/trunk@483 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev преди 13 години
родител
ревизия
21fef4b1e5
променени са 3 файла, в които са добавени 31 реда и са изтрити 3 реда
  1. 16 3
      clish/shell/shell_var.c
  2. 12 0
      tinyrl/tinyrl.c
  3. 3 0
      tinyrl/tinyrl.h

+ 16 - 3
clish/shell/shell_var.c

@@ -49,10 +49,23 @@ void clish_shell__expand_viewid(const char *viewid, lub_bintree_t *tree,
 static char *find_context_var(const char *name, clish_context_t *this)
 {
 	char *result = NULL;
-
-	if (!this->cmd)
+	clish_shell_t *shell = this->shell;
+
+	if (!lub_string_nocasecmp(name, "__width")) {
+		char tmp[5];
+		snprintf(tmp, sizeof(tmp), "%u",
+			tinyrl__get_width(shell->tinyrl));
+		tmp[sizeof(tmp) - 1] = '\0';
+		result = strdup(tmp);
+	} else if (!lub_string_nocasecmp(name, "__height")) {
+		char tmp[5];
+		snprintf(tmp, sizeof(tmp), "%u",
+			tinyrl__get_height(shell->tinyrl));
+		tmp[sizeof(tmp) - 1] = '\0';
+		result = strdup(tmp);
+	} else if (!this->cmd) { /* The vars dependent on command */
 		return NULL;
-	if (!lub_string_nocasecmp(name, "__full_cmd")) {
+	} else if (!lub_string_nocasecmp(name, "__full_cmd")) {
 		result = lub_string_dup(clish_command__get_name(this->cmd));
 	} else if (!lub_string_nocasecmp(name, "__cmd")) {
 		result = lub_string_dup(clish_command__get_name(

+ 12 - 0
tinyrl/tinyrl.c

@@ -1317,3 +1317,15 @@ void tinyrl_limit_line_length(tinyrl_t * this, unsigned length)
 }
 
 /*--------------------------------------------------------- */
+extern unsigned tinyrl__get_width(const tinyrl_t *this)
+{
+	return tinyrl_vt100__get_width(this->term);
+}
+
+/*--------------------------------------------------------- */
+extern unsigned tinyrl__get_height(const tinyrl_t *this)
+{
+	return tinyrl_vt100__get_height(this->term);
+}
+
+/*--------------------------------------------------------- */

+ 3 - 0
tinyrl/tinyrl.h

@@ -222,6 +222,9 @@ extern void tinyrl_limit_line_length(
          */
 					    unsigned length);
 
+extern unsigned tinyrl__get_width(const tinyrl_t *instance);
+extern unsigned tinyrl__get_height(const tinyrl_t *instance);
+
 _END_C_DECL
 #endif				/* _tinyrl_tinyrl_h */
 /** @} tinyrl_tinyrl */