다트 대화형 셸
Source: Dev.to
모든 현대 언어는 REPL을 가지고 있어야 합니다. Erlang, Elixir, Haskell, Clojure, Ocaml, Python … 모두가 설계 단계에서 애플리케이션과 상호작용할 수 있는 쉘 같은 기능을 제공합니다. 저에게는 이것이 거의 필수적이라 할 수 있습니다. 최종 커밋에 코드를 추가하기 전에 함수를 테스트하거나, 빠른 아이디어를 스케치하는 데 사용할 수 있기 때문이죠. Dart를 배우기 시작했을 때 기본적으로 REPL이 제공되지 않아 조금 아쉬웠는데, 누군가 [interactive](https://pub.dev/packages/interactive) 패키지를 만들어 이 문제를 해결했습니다! 새 프로젝트 myrepl을 만들어 확인해 보겠습니다.
$ dart create myrepl
Creating myrepl using template console...
.gitignore
analysis_options.yaml
CHANGELOG.md
pubspec.yaml
README.md
bin/myrepl.dart
lib/myrepl.dart
test/myrepl_test.dart
Running pub get... 0.3s
Resolving dependencies...
Downloading packages...
Changed 48 dependencies!
Created project myrepl in myrepl! In order to get started, run the following commands:
cd myrepl
dart run
$ cd myrepl
Enter fullscreen mode
Exit fullscreen mode
보통 새 의존성은 dart pub add 로 추가합니다. interactive는 12개의 의존성을 가지고 있으니, dev 환경에만 추가하는 것이 좋습니다.
$ dart pub add interactive
Resolving dependencies...
Downloading packages...
meta 1.18.3 (was 1.18.2)
vm_service 11.10.0 (15.2.0 available)
Building package executables... (2.5s)
Built interactive:interactive.
Installed executable interactive.
Warning: Pub installs executables into $HOME/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, .zshrc etc.):
export PATH="$PATH":"$HOME/.pub-cache/bin"
Activated interactive 1.4.1.
$ file ${HOME}/.pub-cache/bin/interactive
${HOME}/.pub-cache/bin/interactive: a sh script, ASCII text executable
Enter fullscreen mode
Exit fullscreen mode
${HOME}/.pub-cache/bin/interactive 파일은 Dart VM을 사용해 interactive 패키지를 실행하는 간단한 쉘 스크립트입니다. 실행되는 명령은 아래와 같습니다. 즉, interactive 패키지만 설치돼 있다면 시스템 어디서든 이 코드를 실행할 수 있습니다(다트 프로젝트 디렉터리가 아닌 곳에서는 오류가 발생할 수 있습니다).
dart pub -v global run interactive:interactive "$@"
Enter fullscreen mode
Exit fullscreen mode
이제 Dart bin 디렉터리를 PATH에 추가해 보겠습니다.
$ export PATH="${PATH}:${HOME}/.pub-cache/bin"
Enter fullscreen mode
Exit fullscreen mode
좋습니다! 이제 interactive 명령을 실행해 보겠습니다(이제 PATH에 포함되어 있습니다).
$ interactive
Run: /bin/dart [--enable-vm-service=34273, file:///bin/interactive.dart-3.11.5.snapshot, --vm-service-was-enabled]
Workspace: /tmp/dart_interactive_workspace_2026-06-04T163359990891
The Dart VM service is listening on http://127.0.0.1:34273/HveG-LmYIiQ=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:34273/HveG-LmYIiQ=/devtools/?uri=ws://127.0.0.1:34273/HveG-LmYIiQ=/ws
>>>
Enter fullscreen mode
Exit fullscreen mode
명령이 >>> 프롬프트가 있는 쉘을 호출합니다. 이제 Dart 코드를 입력하면 어떻게 될까요?
>>> 1+1
2
>>> class Meh { String _meh = ""; Meh(String meh) : this._meh = meh; String toString() => "${_meh}!"; }
>>> Meh("test")
test!
>>> import 'dart:async';
>>> Future t() { return 1; }
[WARNING 2026-06-04 20:25:05.859183] Error: Hot reload failed, maybe because code has syntax error?
>>> Future t() async { return 1; }
>>> t().then((x) => print(x))
Instance of 'Future'
>>> 1
Enter fullscreen mode
Exit fullscreen mode
동작합니다! interactive는 현대 언어가 제공하는 것과 같은 방식으로 동적으로 Dart 코드를 만들 수 있게 해 줍니다. 정말 멋지죠! 라인 앞에 ! 를 붙이면 시스템 명령도 실행할 수 있습니다.
>>> !ls
lib
pubspec.lock
pubspec.yaml
>>> !pwd
/tmp/dart_interactive_workspace_2026-06-04T201405364736
Enter fullscreen mode
Exit fullscreen mode
결론
훌륭한 프로젝트이며 SDK에 포함된다면 더 좋을 것 같습니다! 현재는 작동하지만 다소 불안정하고 아직 완성되지 않은 느낌이 듭니다. 쉘은 동작하지만 가끔 느릴 수 있습니다. devtools 가 기본적으로 시작되는 점도 좋은 기능입니다. 제가 바라는 점은 다음과 같습니다.
- 명령이 실행될 때마다 증가하는 성공적인 커맨드 라인 인덱스 카운터 추가
- 멀티라인 지원을 위한
...표시 제거 (복사·붙여넣기 시 번거로움) @profile로 애플리케이션을 프로파일링하거나@memory로 메모리 사용량을 확인하는 등devtools를 쉘에 직접 통합- 상태와 명령 히스토리를 저장하고 복원하는 세션 저장 기능
- 디버거 및 트레이서 통합
help(Object)와 같은 문서·매뉴얼 통합- 탭 키를 눌렀을 때 클래스·함수·명령 자동 완성
- 커스텀 쉘을 만들 수 있는 핸들러·후크·기타 기능
더 알고 싶다면 아래 링크들을 참고하세요.
interactive패키지 (pub.dev)- 공식
interactive패키지 소스 코드 (GitHub) interactiveAPI 문서
보너스: devtools
interactive를 테스트하면서 Dart devtools 스위트를 발견했습니다. Dart 가상 머신 덕분에 애플리케이션을 디버깅·추적·프로파일링할 수 있는 아주 멋진 도구입니다. 이 도구들은 BEAM(예: observer, debugger 등)에서 제공하는 여러 툴과 비슷하게 동작합니다. 아래는 앞서 만든 프로젝트에서 캡처한 화면들입니다.
[



