Browse Source

Add columns override option.

Signed-off-by: Bradley Smith <[email protected]>
Bradley Smith 14 years ago
parent
commit
354b2e2fb2
3 changed files with 25 additions and 6 deletions
  1. 5 2
      src/mssh-window.c
  2. 2 1
      src/mssh-window.h
  3. 18 3
      src/mssh.c

+ 5 - 2
src/mssh-window.c

@@ -193,7 +193,9 @@ void mssh_window_relayout(MSSHWindow *window)
 	GConfClient *client;
 	GConfEntry *entry;
 	int i, len = window->terminals->len;
-	int cols = (len < window->columns) ? len : window->columns;
+    int wcols = window->columns_override ? window->columns_override :
+        window->columns;
+	int cols = (len < wcols) ? len : wcols;
 	int rows = (len + 0.5) / cols;
 
 	for(i = 0; i < len; i++)
@@ -352,13 +354,14 @@ static void mssh_window_init(MSSHWindow* window)
 }
 
 void mssh_window_start_session(MSSHWindow* window, char **env,
-	GArray *hosts)
+	GArray *hosts, long cols)
 {
 	int i, j, k;
 	int nhosts = hosts->len;
 	int rows = (nhosts / 2) + (nhosts % 2);
 
 	window->env = env;
+    window->columns_override = cols;
 
 	for(i = 0; i < rows; i++)
 	{

+ 2 - 1
src/mssh-window.h

@@ -26,6 +26,7 @@ typedef struct
 	GArray *terminals;
 	char **env;
 	int columns;
+	int columns_override;
 	int timeout;
 	gboolean close_ended_sessions;
 	gboolean exit_on_all_closed;
@@ -40,7 +41,7 @@ GType mssh_window_get_type(void) G_GNUC_CONST;
 
 GtkWidget* mssh_window_new(void);
 void mssh_window_start_session(MSSHWindow* window, char **env,
-	GArray *hosts);
+	GArray *hosts, long cols);
 void mssh_window_relayout(MSSHWindow *window);
 void mssh_window_session_closed(MSSHTerminal *terminal, gpointer data);
 

+ 18 - 3
src/mssh.c

@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
+#include <errno.h>
 
 #include <gtk/gtk.h>
 
@@ -27,6 +28,8 @@ void usage(const char *argv0)
 		argv0);
 	fprintf(stderr,
 		"  -a, --alias=ALIAS    Open hosts associated with named alias\n");
+    fprintf(stderr,
+        "  -c, --columns=NUM    Override gconf for number of columns\n");
 	fprintf(stderr,
 		"  -h, --help           Display this help and exit\n");
 	fprintf(stderr,
@@ -161,12 +164,14 @@ int main(int argc, char* argv[], char* env[])
 	GtkWidget* window;
 	int c, option_index = 0;
 	char *home, *conffile;
+    long cols = 0;
 	GData **aliases = NULL;
 	GArray *hosts = NULL;
 
 	static struct option long_options[] =
 	{
 		{"alias",	required_argument,	0, 'a'},
+		{"columns",	required_argument,	0, 'c'},
 		{"help",	no_argument,		0, 'h'},
 		{"version",	no_argument,		0, 'V'},
 		{0, 0, 0, 0}
@@ -190,7 +195,7 @@ int main(int argc, char* argv[], char* env[])
 
 	for(;;)
 	{
-		c = getopt_long(argc, argv, "a:hV", long_options, &option_index);
+		c = getopt_long(argc, argv, "a:c:hV", long_options, &option_index);
 
 		if(c == -1)
 			break;
@@ -201,10 +206,20 @@ int main(int argc, char* argv[], char* env[])
 			if(aliases && (hosts = g_datalist_get_data(aliases,
 				optarg)) == NULL)
 			{
-				fprintf(stderr, "Alias '%s' not found\n", optarg);
+				fprintf(stderr, "Alias '%s' not found\n\n", optarg);
 				usage(argv[0]);
 			}
 			break;
+        case 'c':
+            errno = 0;
+            cols = strtol(optarg, NULL, 10);
+            if(cols <= 0 || errno != 0)
+            {
+				fprintf(stderr, "Invalid number of columns '%s'\n\n",
+                    optarg);
+				usage(argv[0]);
+            }
+            break;
 		case 'h':
 			usage(argv[0]);
 			break;
@@ -271,7 +286,7 @@ int main(int argc, char* argv[], char* env[])
 	g_signal_connect(G_OBJECT(window), "destroy",
 		G_CALLBACK(on_mssh_destroy), NULL);
 
-	mssh_window_start_session(MSSH_WINDOW(window), env, hosts);
+	mssh_window_start_session(MSSH_WINDOW(window), env, hosts, cols);
 
 	gtk_widget_show_all(window);
 	gtk_main();