memberGet method

  1. @override
dynamic memberGet(
  1. String varName, {
  2. String? from,
})
override

Fetch a member by the varName, in the form of

object.varName

varName must be of String type.

Implementation

@override
dynamic memberGet(String varName, {String? from}) {
  switch (varName) {
    case 'Console.write':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          stdout.write(positionalArgs.first);
    case 'Console.writeln':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          stdout.writeln(positionalArgs.first);
    case 'Console.getln':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) {
        if (positionalArgs.isNotEmpty) {
          stdout.write('${positionalArgs.first}');
        } else {
          stdout.write('>');
        }
        return stdin.readLineSync();
      };
    case 'Console.eraseLine':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          stdout.write('\x1B[1F\x1B[1G\x1B[1K');
    case 'Console.setTitle':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          stdout.write('\x1b]0;${positionalArgs.first}\x07');
    case 'Console.clear':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          stdout.write('\x1B[2J\x1B[0;0H');
    default:
      throw HTError.undefined(varName);
  }
}