@@ -56,6 +56,13 @@ typedef struct sgttyb conmode;
5656#include <conio.h>
5757typedef DWORD conmode ;
5858
59+ #ifndef ENABLE_WRAP_AT_EOL_OUTPUT
60+ # define ENABLE_WRAP_AT_EOL_OUTPUT 0x0002
61+ #endif
62+ #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
63+ # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
64+ #endif
65+
5966#define LAST_ERROR rb_w32_map_errno(GetLastError())
6067#define SET_LAST_ERROR (errno = LAST_ERROR, 0)
6168
@@ -750,6 +757,70 @@ conmode_raw_new(int argc, VALUE *argv, VALUE obj)
750757 return conmode_new (rb_obj_class (obj ), & t );
751758}
752759
760+ #ifdef _WIN32
761+ /*
762+ * call-seq:
763+ * mode.virtual_terminal_processing? -> true or false
764+ *
765+ * Returns whether virtual terminal sequences are processed on output.
766+ */
767+ static VALUE
768+ conmode_virtual_terminal_processing_p (VALUE obj )
769+ {
770+ conmode * t = rb_check_typeddata (obj , & conmode_type );
771+ return (* t & ENABLE_VIRTUAL_TERMINAL_PROCESSING ) ? Qtrue : Qfalse ;
772+ }
773+
774+ /*
775+ * call-seq:
776+ * mode.virtual_terminal_processing = enabled
777+ *
778+ * Enables or disables virtual terminal sequence processing in +mode+.
779+ * Assign +mode+ to IO#console_mode= to apply the change.
780+ */
781+ static VALUE
782+ conmode_set_virtual_terminal_processing (VALUE obj , VALUE enabled )
783+ {
784+ conmode * t = rb_check_typeddata (obj , & conmode_type );
785+ if (RTEST (enabled ))
786+ * t |= ENABLE_VIRTUAL_TERMINAL_PROCESSING ;
787+ else
788+ * t &= ~ENABLE_VIRTUAL_TERMINAL_PROCESSING ;
789+ return obj ;
790+ }
791+
792+ /*
793+ * call-seq:
794+ * mode.wrap_at_eol_output? -> true or false
795+ *
796+ * Returns whether output wraps at the end of a line.
797+ */
798+ static VALUE
799+ conmode_wrap_at_eol_output_p (VALUE obj )
800+ {
801+ conmode * t = rb_check_typeddata (obj , & conmode_type );
802+ return (* t & ENABLE_WRAP_AT_EOL_OUTPUT ) ? Qtrue : Qfalse ;
803+ }
804+
805+ /*
806+ * call-seq:
807+ * mode.wrap_at_eol_output = enabled
808+ *
809+ * Enables or disables wrapping at the end of a line in +mode+.
810+ * Assign +mode+ to IO#console_mode= to apply the change.
811+ */
812+ static VALUE
813+ conmode_set_wrap_at_eol_output (VALUE obj , VALUE enabled )
814+ {
815+ conmode * t = rb_check_typeddata (obj , & conmode_type );
816+ if (RTEST (enabled ))
817+ * t |= ENABLE_WRAP_AT_EOL_OUTPUT ;
818+ else
819+ * t &= ~ENABLE_WRAP_AT_EOL_OUTPUT ;
820+ return obj ;
821+ }
822+ #endif
823+
753824/*
754825 * call-seq:
755826 * io.console_mode -> mode
@@ -2310,5 +2381,11 @@ InitVM_console(void)
23102381 rb_define_method (cConmode , "echo=" , conmode_set_echo , 1 );
23112382 rb_define_method (cConmode , "raw!" , conmode_set_raw , -1 );
23122383 rb_define_method (cConmode , "raw" , conmode_raw_new , -1 );
2384+ #ifdef _WIN32
2385+ rb_define_method (cConmode , "virtual_terminal_processing?" , conmode_virtual_terminal_processing_p , 0 );
2386+ rb_define_method (cConmode , "virtual_terminal_processing=" , conmode_set_virtual_terminal_processing , 1 );
2387+ rb_define_method (cConmode , "wrap_at_eol_output?" , conmode_wrap_at_eol_output_p , 0 );
2388+ rb_define_method (cConmode , "wrap_at_eol_output=" , conmode_set_wrap_at_eol_output , 1 );
2389+ #endif
23132390 }
23142391}
0 commit comments