[Mono-dev] Terminal config for mono csharp shell?
Cyd Haselton
chaselton at gmail.com
Sat Jun 13 12:19:31 UTC 2015
Quick update with additional info:
Came across this test program on bugzilla and modified it for the ret variable in console-unix.c:
ocalhost:/bld/mono/mono-4.0.0$ cat ~/sigtest.c
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>
int main ()
{
struct winsize ws;
int ret;
if (ioctl (STDIN_FILENO, TIOCGWINSZ, &ws) == 0)
{
printf ("%d %d\n", ((ws.ws_col << 16) | ws.ws_row)); return 0;
}
printf ("ioctl failed\n");
return 1;
}
I had to add #include <termios.h> for it to work properly.
The output:
localhost:/bld/mono/mono-4.0.0$ ~/sigtest
5570606 33912
The above numbers are what's being output from the 'static int terminal_get_dimensions(void)' function in console-unix.c, which looks like this:
174
175 static gint32 cols_and_lines;
176
177 #ifdef TIOCGWINSZ
178 static int
179 terminal_get_dimensions (void)
180 {
181 struct winsize ws;
182 int ret;
183 int save_errno = errno;
184
185 if (ioctl (STDIN_FILENO, TIOCGWINSZ, &ws) == 0){
186 ret = (ws.ws_col << 16) | ws.ws_row;
187 errno = save_errno;
188 return ret;
189 }
190 return -1;
191 }
That function is used again in console-unix.c here:
306 MONO_SIG_HANDLER_FUNC (static, sigwinch_handler)
307 {
308 int dims = terminal_get_dimensions ();
309 if (dims != -1)
310 cols_and_lines = dims;
311
312 // Call previous handler
313 if (save_sigwinch.sa_sigaction != NULL &&
314 save_sigwinch.sa_sigaction != (void *)SIG_DFL &&
315 save_sigwinch.sa_sigaction != (void *)SIG_IGN)
316 (*save_sigwinch.sa_sigaction) (MONO_SIG_HANDLER_PARAMS);
317 }
I took a chance that dims refers to columns and lines and not # of characters in columns and lines or the # of chars possible in a window with x columns and y lines and changed this:
ret = (ws.ws_col << 16) | ws.ws_row;
to this:
ret = ws.ws_col | ws.ws_row;
Re-building now.
On June 12, 2015 1:02:49 AM CDT, Robert N <sushihangover at outlook.com> wrote:
>
>Sorry, been swamped... I'm not sure about the outclass.h, I'll have to
>take a look... I do know that resizing the csharp repo on os-x's
>terminal causes havoc on the its output and the input/output cursor is
>incorrectly moved, that that point it is taking input and sending out
>to the wrong line of the window, but it does not crash as in your case.
>
>> Date: Wed, 10 Jun 2015 11:20:46 -0500
>> Subject: Re: [Mono-dev] Terminal config for mono csharp shell?
>> From: chaselton at gmail.com
>> To: sushihangover at outlook.com
>> CC: mono-devel-list at lists.ximian.com
>>
>> I'm revisiting this because I uncovered a larger, possibly related,
>> problem with running the newly built csharp REPL.
>>
>> When resizing the terminal, csharp exits unexpectedly. Running
>strace
>> in a separate terminal and attaching it to the csharp PID shows the
>> csharp REPL segfaulting when the terminal is resized (at
>> SIGWINCH...specifically right after the following line is
>> called/executed:
>>
>> ioctl(0, TIOCGWINSZ, {ws_row=59, ws_col=85, ws_xpixel=0,
>ws_ypixel=0}) = 0
>>
>> My sysroot has an asm/ioctls.h...I'm guessing that it needs to be
>> added to console-unix.c or console-io.c...possibly both. Am I in the
>> right ballpark?
>>
>> On Sat, Jun 6, 2015 at 10:41 PM, Robert N <sushihangover at outlook.com>
>wrote:
>> >
>> >
>> > stty sane make sense in terms of a TERM=linux and either a messed
>up/missing termcap and/or missing capabilities during autogen/configure
>and shell that is not quite right...
>> >
>> > The fact that the console.unix.c works across all the std linux
>flavors and os-x would suggest that something in your environment is
>different. Not sure what your 'droid dev environment is like, but if
>you can build/debug mono, you can look at how it is init & exiting in
>the app-domain.c/console-io.c/console-unix.c routines.
>> >
>> > It should 'just work', but that requires a very clean environment
>as Mono does an very generic (iffy IMHO) job of tty exiting (also
>init'ing). If you look at the ConsoleDriver the extent of the tty
>exit/teardown is 'string' that is sent is a hardcoded DC1 signal (0x11)
>which is Ctrl-Q (XON). You can browse the native driver function in
>console-unix.c, it is running on a gc'd thread, the std c lib function
>atexit is called with the tty teardown function and it does a very
>generic teardown (flushing the pipes and setting the ECHO env to true).
>> >
>> > Is this right or wrong? Depends upon who you ask ;-) Programs
>written in python have this this issue all the time with using no echo
>tty mode and properly exiting, it is usually a threading issue, but
>hard to prevent. A lot of P-coders just place an os.system('stty sane')
>in their exit code, perl coders place system("stty sane"); curses
>users should always use endwin(); reset(); to clean things up, etc...
>> >
>> > The fact that the console.unix.c works across all the std linux
>flavors and os-x would suggest that something in your environment is
>different. Not sure what your 'droid dev environment is like, but if
>you can build/debug mono, you can look at how it is init & exiting in
>the app-domain.c/console-io.c/console-unix.c routines.
>> >
>> > ________________________________
>> > From: chaselton at gmail.com
>> > Date: Sat, 6 Jun 2015 19:39:16 -0500
>> > To: mono-devel-list at lists.ximian.com
>> > Subject: Re: [Mono-dev] Terminal config for mono csharp shell?
>> >
>> > Additionally, running 'stty sane' after exiting the REPL solves the
>problem. Maybe there is a way to set the REPL to run a command on
>quitting?
>> >
>> > On June 6, 2015 8:04:47 AM CDT, Cyd Haselton <chaselton at gmail.com>
>wrote:
>> >
>> > Are there any special terminal and/or shell settings I should set
>for the csharp shell?
>> >
>> > csharp works okay...minus some cursor jumping...but after quitting
>the console shell behaves oddly until I exit it and re-enter.
>> >
>> > Example:
>> > /home/kbox $ csharp
>> > Mono C# Shell, type "help;" for help
>> > Enter statements below.
>> > csharp> DateTime.Now 06/06/2015 13:00:31
>> > csharp> help "Static methods:
>> > Describe (object); - Describes the object's type
>> > LoadPackage (package); - Loads the given Package (like -pkg:FILE)
>> > LoadAssembly (assembly); - Loads the given assembly (like
>-r:ASSEMBLY)
>> > ShowVars (); - Shows defined local variables.
>> > ShowUsing (); - Show active using declarations.
>> > Prompt - The prompt used by the C# shell
>> > ContinuationPrompt - The prompt for partial input
>> > Time (() => { }); - Times the specified code
>> > print (obj); - Shorthand for Console.WriteLine
>> > quit; - You'll never believe it - this quits the repl!
>> > help; - This help text
>> > TabAtStartCompletes - Whether tab will complete even on empty lines
>> > "
>> > csharp> quit
>> >
>> > Environment shell after quitting:
>> > /home/kbox $ /home/kbox $ /home/kbox $ /home/kbox $ /home/kbox $
>/home/kbox $ /home/kbox $ >
>/data/data/jackpal.androidterm/kbox2/bin/bash: \: not found
>> > /home/kbox $ /home/kbox $ /home/kbox $ /home/kbox $ /home/kbox $
>/home/kbox $
>> >
>> > After exiting environment shell...you can't see the 'exit' command
>I typed:
>> > /home/kbox $ 127|u0_a186 at altev:/ $
>> > 127|u0_a186 at altev:/ $
>> > 127|u0_a186 at altev:/ $
>> > 127|u0_a186 at altev:/ $
>> > 127|u0_a186 at altev:/ $
>> >
>> > Re-entering the environment shell:
>> > 127|u0_a186 at altev:/ $
>/data/data/jackpal.androidterm/kbox2/bin/kbox_shell
>> > /home/kbox $
>> > /home/kbox $
>> > /home/kbox $
>> > /home/kbox $
>> >
>> >
>> > --
>> > Sent from my Android device with K-9 Mail. Please excuse my
>brevity.
>> > _______________________________________________ Mono-devel-list
>mailing list Mono-devel-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
More information about the Mono-devel-list
mailing list