ansi_escape.diff

Usaku NAKAMURA, 05/09/2012 11:04 AM

Download (6.1 KB)

View differences:

bootstraptest/runner.rb (working copy)
113 113
  @progress = %w[- \\ | /]
114 114
  @progress_bs = "\b" * @progress[0].size
115 115
  @tty = !@verbose && $stderr.tty?
116
  if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
116
  #if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
117
  if @tty and /dumb/ !~ ENV["TERM"]
117 118
    @passed = "\e[#{ENV['PASSED_COLOR']||'32'}m"
118 119
    @failed = "\e[#{ENV['FAILED_COLOR']||'31'}m"
119 120
    @reset = "\e[m"
sample/test.rb (working copy)
10 10
  @rotator = %w[- \\ | /]
11 11
  @bs = "\b" * @rotator[0].size
12 12
  @tty = STDERR.tty?
13
  if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
13
  #if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
14
  if @tty and /dumb/ !~ ENV["TERM"]
14 15
    @passed = "\e[#{ENV['PASSED_COLOR']||'32'}m"
15 16
    @failed = "\e[#{ENV['FAILED_COLOR']||'31'}m"
16 17
    @reset = "\e[m"
lib/test/unit.rb (working copy)
712 712
      def initialize # :nodoc:
713 713
        super
714 714
        @tty = $stdout.tty?
715
        if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
715
        #if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
716
        if @tty and /dumb/ !~ ENV["TERM"]
716 717
          @failed_color = "\e[#{ENV['FAILED_COLOR']||'31'}m"
717 718
          @reset_color = "\e[m"
718 719
        else
win32/win32.c (working copy)
2452 2452
    return -1;
2453 2453
}
2454 2454

  
2455
/* License: Ruby's */
2455 2456
void
2456 2457
rb_w32_fdset(int fd, fd_set *set)
2457 2458
{
......
5847 5848
    HANDLE handle;
5848 5849
    DWORD dwMode, reslen;
5849 5850
    VALUE str = strarg;
5851
    rb_encoding *utf16 = rb_enc_find("UTF-16LE");
5852
    char *ptr;
5853
    long len;
5854
    static WORD attr = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5850 5855

  
5851 5856
    if (disable) return -1L;
5852 5857
    handle = (HANDLE)_osfhnd(fd);
......
5854 5859
	!rb_econv_has_convpath_p(rb_enc_name(rb_enc_get(str)), "UTF-16LE"))
5855 5860
	return -1L;
5856 5861

  
5857
    str = rb_str_encode(str, rb_enc_from_encoding(rb_enc_find("UTF-16LE")),
5862
    str = rb_str_encode(str, rb_enc_from_encoding(utf16),
5858 5863
			ECONV_INVALID_REPLACE|ECONV_UNDEF_REPLACE, Qnil);
5859
    if (!WriteConsoleW(handle, (LPWSTR)RSTRING_PTR(str), RSTRING_LEN(str)/2,
5860
		       &reslen, NULL)) {
5861
	if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
5862
	    disable = TRUE;
5863
	return -1L;
5864
    ptr = RSTRING_PTR(str);
5865
    len = RSTRING_LEN(str);
5866
    while (len > 0) {
5867
	long pos = rb_memsearch(L"\x1B[", 4, ptr, len, utf16);
5868
	long curlen = pos < 0 ? len : pos;
5869
	if (curlen > 0) {
5870
	    if (!WriteConsoleW(handle, (LPWSTR)ptr, curlen/2, &reslen, NULL)) {
5871
		if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
5872
		    disable = TRUE;
5873
		return -1L;
5874
	    }
5875
	    ptr += curlen;
5876
	    len -= curlen;
5877
	}
5878
	if (pos >= 0) {
5879
	    int seq = 0;
5880
	    int rev = 0;
5881
	    ptr += 4;
5882
	    len -= 4;
5883
	    while (len > 1) {
5884
		WCHAR w = *(LPWSTR)ptr;
5885
		if (w == L';' || w == L'm') {
5886
		    ptr += 2;
5887
		    len -= 2;
5888
		    switch (seq) {
5889
		      case 0:
5890
			attr = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5891
			rev = 0;
5892
			break;
5893
		      case 4:
5894
			attr |= COMMON_LVB_UNDERSCORE;
5895
			break;
5896
		      case 7:
5897
			rev = 1;
5898
			break;
5899

  
5900
		      case 30:
5901
			attr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
5902
		      case 17:
5903
		      case 31:
5904
			attr = attr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN) | FOREGROUND_RED;
5905
			break;
5906
		      case 18:
5907
		      case 32:
5908
			attr = attr & ~(FOREGROUND_BLUE | FOREGROUND_RED) | FOREGROUND_GREEN;
5909
			break;
5910
		      case 19:
5911
		      case 33:
5912
			attr = attr & ~FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5913
			break;
5914
		      case 20:
5915
		      case 34:
5916
			attr = attr & ~(FOREGROUND_GREEN | FOREGROUND_RED) | FOREGROUND_BLUE;
5917
			break;
5918
		      case 21:
5919
		      case 35:
5920
			attr = attr & ~FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED;
5921
			break;
5922
		      case 22:
5923
		      case 36:
5924
			attr = attr & ~FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
5925
			break;
5926
		      case 23:
5927
		      case 37:
5928
			attr |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
5929
			break;
5930

  
5931
		      case 40:
5932
			attr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
5933
		      case 41:
5934
			attr = attr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN) | BACKGROUND_RED;
5935
			break;
5936
		      case 42:
5937
			attr = attr & ~(BACKGROUND_BLUE | BACKGROUND_RED) | BACKGROUND_GREEN;
5938
			break;
5939
		      case 43:
5940
			attr = attr & ~BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
5941
			break;
5942
		      case 44:
5943
			attr = attr & ~(BACKGROUND_GREEN | BACKGROUND_RED) | BACKGROUND_BLUE;
5944
			break;
5945
		      case 45:
5946
			attr = attr & ~BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED;
5947
			break;
5948
		      case 46:
5949
			attr = attr & ~BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN;
5950
			break;
5951
		      case 47:
5952
			attr |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
5953
			break;
5954
		    }
5955
		    if (rev) {
5956
			WORD attr2 = attr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED) | ((attr & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)) << 4) | ((attr & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED)) >> 4);
5957
			SetConsoleTextAttribute(handle, attr2);
5958
		    }
5959
		    else {
5960
			SetConsoleTextAttribute(handle, attr);
5961
		    }
5962
		    if (w == L'm') {
5963
			break;
5964
		    }
5965
		    seq = 0;
5966
		}
5967
		else if (w >= L'0' && w <= L'9') {
5968
		    ptr += 2;
5969
		    len -= 2;
5970
		    seq = seq * 10 + w - L'0';
5971
		}
5972
		else {
5973
		    break;
5974
		}
5975
	    }
5976
	}
5864 5977
    }
5978
    RB_GC_GUARD(str);
5865 5979
    return (long)reslen;
5866 5980
}
5867 5981