규약
동작은 transform(text)를 정의합니다. 돌려준 값은 텍스트로 바뀌어 지금 쓰고 있는 자리에 들어갑니다.
def transform(text):
return text.upper()아무것도 넣지 않으려면 None을 돌려주세요. 빠르게 시험할 때는 함수 대신 최상위 result 변수에 값을 넣어도 됩니다.
텍스트가 오는 곳
| 입력 | 액션이 받는 값 |
|---|---|
| 없음 | 처음부터 텍스트를 생성해요. transform(""). |
| 현재 단어 | 입력 중인 단어를 transform(text)에 전달해요. |
| 선택 영역 | 선택한 텍스트를 넘깁니다. 선택한 것이 없으면 아무것도 넘기지 않습니다. |
| 현재 줄 | 커서가 있는 줄을 넘깁니다. |
| 현재 문장 | 커서가 있는 문장을 넘깁니다. |
| 커서 앞의 텍스트 | 커서 앞의 모든 내용을 전달해요. |
| 커서 뒤 텍스트 | 커서 뒤의 모든 내용을 넘깁니다. |
| 입력란 전체 | 커서 앞뒤를 모두 포함해 입력란 전체를 넘깁니다. |
| 클립보드 | 클립보드 텍스트를 전달해요. 전체 접근 허용이 필요해요. |
‘입력 대체’는 결과가 들어온 자리를 차지할지 정합니다. 입력란을 읽는 모든 소스에 적용됩니다. ‘없음’과 ‘클립보드’는 문서 안에 대체할 것이 없으므로 결과가 언제나 삽입됩니다.
def transform(text):
words = len(text.split())
return f"{words} words"키보드에 요청하기
액션은 문자열 하나를 반환하는 대신 패널과 같은 명령을 쓸 수 있습니다. 편집을 두 번 이상 하거나 커서를 특정 위치에 두려면 이 방법을 씁니다.
def transform(text):
replace(len(text), "(" + text + ")")
move_cursor(-1)toast()와 close()는 패널의 것입니다. 액션에는 메시지를 띄울 자기 화면이 없습니다. 다만 작성하는 동안 콘솔에는 둘 다 나타납니다.
언어
스크립트는 CPython이 아니라 Clink가 만든 인터프리터에서 돌아갑니다. 컴프리헨션, lambda, 튜플, 집합, f-문자열 서식, try와 except 같은 파이썬의 쓸모 있는 부분을 읽고, 나머지는 줄 번호를 알려 주는 메시지로 거절합니다.
자료형
intfloatstrboolNonelisttupledictset
키워드
ifelifelsewhileforindefreturnbreakcontinuepassTrueFalseNoneandornotlambdatryexceptfinallyraiseimportfromasisdelglobal
내장 함수
lenstrreprprintintfloatboolabsroundminmaxsumrangesortedreversedlistdictsettupleenumeratezipordchranyalltypemapfilterdivmodpowhexbinoctformatisinstancecallable
문자열 메서드
upperlowercasefoldtitlecapitalizeswapcasestriplstriprstripreplacesplitrsplitsplitlinesjoinstartswithendswithfindrfindindexrindexcountpartitionrpartitionzfillljustrjustcenterisdigitisnumericisalphaisalnumisspaceisupperisloweristitleremoveprefixremovesuffixformat
리스트 메서드
appendextendpopinsertremoveindexcountsortreverseclearcopy
딕셔너리 메서드
keysvaluesitemsgetpoppopitemsetdefaultupdateclearcopy
집합 메서드
adddiscardremovepopclearcopyupdateunionintersectiondifferencesymmetric_differenceissubsetissupersetisdisjoint
튜플 메서드
countindex
정규식 매치 메서드
groupgroupsgroupdictstartendspan
예외
ExceptionValueErrorTypeErrorKeyErrorIndexErrorNameErrorZeroDivisionErrorAttributeErrorRuntimeErrorStopIteration
거부
classwithnonlocalassertyieldasyncawaitmatch
네임스페이스
가져올 수 있는 네임스페이스는 다음이 전부입니다. 모두 계산만 할 뿐, 스크립트가 닿을 수 있는 파일 시스템도 네트워크도 프로세스도 없습니다.
import json
dumpsloads
import math
acosasinatanatan2ceilcombcopysigncosdegreeseexpfabsfactorialfloorfmodgcdhypotinfisfiniteisinfisnanlcmloglog10log2nanpipowprodradianssinsqrttantautrunc
import random
choicechoicesrandintrandomrandrangesampleseedshuffleuniform
import re
DOTALLIIGNORECASEMMULTILINESescapefindallfinditerfullmatchmatchsearchsplitsubsubn
import sys
version
import time
formatmonotonicpartstime
import re
def transform(text):
return re.sub(r"\s+", " ", text).strip()정규식 엔진은 Clink가 직접 만든 것이며, 스크립트의 나머지와 같은 단계 예산을 씁니다. 그래서 그냥 두면 끝나지 않을 패턴도 키보드가 멎는 대신 오류로 끝납니다. 역참조와 전후방 탐색은 지원하지 않습니다.
왜 CPython이 아닌가
키보드 확장에는 빡빡한 메모리 상한이 있고, 넘어서면 iOS가 예고 없이 끝냅니다. Python 런타임 전체는 키보드 옆에 들어가지 않으므로, Clink는 이 일을 위해 쓴 작은 인터프리터를 싣습니다. import도 파일도 네트워크도 없고, 폭주한 스크립트를 끝내는 단계 예산이 있습니다. 끝나는 쪽은 키보드가 아닙니다.
print는 편집기의 콘솔로 갑니다. 쓰고 있는 글 안으로는 절대 들어가지 않습니다.