OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "bin/stdio.h" | 7 #include "bin/stdio.h" |
8 | 8 |
9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 void FUNCTION_NAME(Stdin_SetLineMode)(Dart_NativeArguments args) { | 62 void FUNCTION_NAME(Stdin_SetLineMode)(Dart_NativeArguments args) { |
63 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); | 63 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); |
64 if (Stdin::SetLineMode(enabled)) { | 64 if (Stdin::SetLineMode(enabled)) { |
65 Dart_SetReturnValue(args, Dart_True()); | 65 Dart_SetReturnValue(args, Dart_True()); |
66 } else { | 66 } else { |
67 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 67 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 | 71 |
| 72 void FUNCTION_NAME(Stdin_AnsiSupported)(Dart_NativeArguments args) { |
| 73 bool supported = false; |
| 74 if (Stdin::AnsiSupported(&supported)) { |
| 75 Dart_SetBooleanReturnValue(args, supported); |
| 76 } else { |
| 77 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 78 } |
| 79 } |
| 80 |
| 81 |
72 void FUNCTION_NAME(Stdout_GetTerminalSize)(Dart_NativeArguments args) { | 82 void FUNCTION_NAME(Stdout_GetTerminalSize)(Dart_NativeArguments args) { |
73 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { | 83 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { |
74 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 84 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
75 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 85 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
76 return; | 86 return; |
77 } | 87 } |
78 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 88 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
79 if ((fd != 1) && (fd != 2)) { | 89 if ((fd != 1) && (fd != 2)) { |
80 Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2")); | 90 Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2")); |
81 return; | 91 return; |
82 } | 92 } |
83 | 93 |
84 int size[2]; | 94 int size[2]; |
85 if (Stdout::GetTerminalSize(fd, size)) { | 95 if (Stdout::GetTerminalSize(fd, size)) { |
86 Dart_Handle list = Dart_NewList(2); | 96 Dart_Handle list = Dart_NewList(2); |
87 Dart_ListSetAt(list, 0, Dart_NewInteger(size[0])); | 97 Dart_ListSetAt(list, 0, Dart_NewInteger(size[0])); |
88 Dart_ListSetAt(list, 1, Dart_NewInteger(size[1])); | 98 Dart_ListSetAt(list, 1, Dart_NewInteger(size[1])); |
89 Dart_SetReturnValue(args, list); | 99 Dart_SetReturnValue(args, list); |
90 } else { | 100 } else { |
91 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 101 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
92 } | 102 } |
93 } | 103 } |
94 | 104 |
| 105 |
| 106 void FUNCTION_NAME(Stdout_AnsiSupported)(Dart_NativeArguments args) { |
| 107 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { |
| 108 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
| 109 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
| 110 return; |
| 111 } |
| 112 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
| 113 if ((fd != 1) && (fd != 2)) { |
| 114 Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2")); |
| 115 return; |
| 116 } |
| 117 bool supported = false; |
| 118 if (Stdout::AnsiSupported(fd, &supported)) { |
| 119 Dart_SetBooleanReturnValue(args, supported); |
| 120 } else { |
| 121 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 122 } |
| 123 } |
| 124 |
95 } // namespace bin | 125 } // namespace bin |
96 } // namespace dart | 126 } // namespace dart |
97 | 127 |
98 #endif // !defined(DART_IO_DISABLED) | 128 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |