diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f508d98..c12b85a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,8 +8,6 @@ on: jobs: release: runs-on: ${{ matrix.job.os }} - outputs: - PROJECT_VERSION: ${{ env.PROJECT_VERSION }} env: PROJECT_NAME: "omekasy" strategy: @@ -34,21 +32,22 @@ jobs: - name: Get the release version from the tag shell: bash + id: project_version run: | - echo "PROJECT_VERSION=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_ENV" - echo "Version: ${{ env.PROJECT_VERSION }}" + echo "PROJECT_VERSION=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT" - name: Build release run: cargo build --locked --verbose --release --target=${{ matrix.job.target }} - name: Set up path shell: bash + id: set_bin_path run: | EXE_SUFFIX="" [ "${{ matrix.job.target }}" = "x86_64-pc-windows-msvc" ] && EXE_SUFFIX=".exe" BIN_PATH="target/${{ matrix.job.target }}/release/omekasy${EXE_SUFFIX}" - echo "BIN_PATH=${BIN_PATH}" >> "${GITHUB_ENV}" + echo "BIN_PATH=${BIN_PATH}" >> "$GITHUB_OUTPUT" - name: Strip binary shell: bash @@ -57,21 +56,22 @@ jobs: [ "${{ matrix.job.target }}" = "x86_64-pc-windows-msvc" ] && STRIP="" if [ -n "${STRIP}" ]; then - "${STRIP}" "${{ env.BIN_PATH }}" + "${STRIP}" "${{ steps.set_bin_path.outputs.BIN_PATH }}" fi - name: Create tarball shell: bash + id: create_tarball run: | PKG_SUFFIX=".tar.gz" ; case "${{ matrix.job.target }}" in *-pc-windows-*) PKG_SUFFIX=".zip" ;; esac; - PKG_BASENAME="${PROJECT_NAME}-v${{ env.PROJECT_VERSION }}-${{ matrix.job.target }}" + PKG_BASENAME="${PROJECT_NAME}-v${{ steps.project_version.outputs.PROJECT_VERSION }}-${{ matrix.job.target }}" PKG_PATH="${PKG_BASENAME}${PKG_SUFFIX}" echo "PKG_PATH=${PKG_PATH}" >> "${GITHUB_ENV}" PKG_DIR="archive" mkdir -p "${PKG_DIR}" cp {README.md,LICENSE} "$PKG_DIR" - cp "${{ env.BIN_PATH }}" "${PKG_DIR}" + cp "${{ steps.set_bin_path.outputs.BIN_PATH }}" "${PKG_DIR}" if [ "${{ matrix.job.os }}" = "windows-2019" ]; then 7z a "${PKG_PATH}" "${PKG_DIR}" @@ -87,7 +87,7 @@ jobs: if: ${{ contains(github.ref, '/tags/') }} uses: softprops/action-gh-release@v1 with: - files: ${{ env.PKG_PATH }} + files: ${{ steps.create_tarball.outputs.PKG_PATH }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 485fc5f..c42d830 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,12 @@ Available font for now: - bold-fraktur - monospace - blackboard +- emoji Key bindings in interactive mode: -| Key | Action | -|---|---| -|Ctrl-K|Move cursor up| -|Ctrl-J|Move cursor down| -|Enter|Select| -|Ctrl-C, Esc|Quit| +| Key | Action | +| ----------- | ---------------- | +| Ctrl-K | Move cursor up | +| Ctrl-J | Move cursor down | +| Enter | Select | +| Ctrl-C, Esc | Quit | diff --git a/src/convert.rs b/src/convert.rs index f465a40..a0b4aef 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -24,16 +24,25 @@ impl Converter { .font_mappings .get(&font) .expect("Unexpected font specified"); - source - .iter() - .map(|original| { - if let Some(converted) = mapping.get(original) { - converted - } else { - original - } - }) - .collect() + let converted = source.iter().map(|original| { + if let Some(converted) = mapping.get(original) { + converted + } else { + original + } + }); + + if font == Font::Emoji { + // In this application, we want reginal indicator symbols to be rendered as emoji. + // To prevent them from being rendered as flags, we insert zero-width joiner(U+200C) between each character. + // For a simple implementation, we U+200C between all characters. + converted + .map(|c| c.to_string()) + .collect::>() + .join('\u{200C}'.to_string().as_str()) + } else { + converted.collect() + } } } @@ -213,4 +222,16 @@ mod tests { converter.convert(&source, Font::Blackboard) ); } + + #[test] + fn emoji() { + let converter = setup_converter(); + let source = "8WymXbLV3nINUhOoQkKGfuY9HsZSC675jzBEtATDFMRgPpeaxiJcr0q4l1w2dv" + .chars() + .collect::>(); + assert_eq!( + "8โ€Œ๐Ÿ‡ฝโ€Œ๐Ÿ‡พโ€Œ๐Ÿ‡ฒโ€Œ๐Ÿ‡พโ€Œ๐Ÿ‡งโ€Œ๐Ÿ‡ฒโ€Œ๐Ÿ‡ผโ€Œ3โ€Œ๐Ÿ‡ณโ€Œ๐Ÿ‡ฏโ€Œ๐Ÿ‡ดโ€Œ๐Ÿ‡ปโ€Œ๐Ÿ‡ญโ€Œ๐Ÿ‡ตโ€Œ๐Ÿ‡ดโ€Œ๐Ÿ‡ทโ€Œ๐Ÿ‡ฐโ€Œ๐Ÿ‡ฑโ€Œ๐Ÿ‡ญโ€Œ๐Ÿ‡ซโ€Œ๐Ÿ‡บโ€Œ๐Ÿ‡ฟโ€Œ9โ€Œ๐Ÿ‡ฎโ€Œ๐Ÿ‡ธโ€Œ๐Ÿ‡ฟโ€Œ๐Ÿ‡นโ€Œ๐Ÿ‡ฉโ€Œ6โ€Œ7โ€Œ5โ€Œ๐Ÿ‡ฏโ€Œ๐Ÿ‡ฆโ€Œ๐Ÿ‡จโ€Œ๐Ÿ‡ซโ€Œ๐Ÿ‡นโ€Œ๐Ÿ‡งโ€Œ๐Ÿ‡บโ€Œ๐Ÿ‡ชโ€Œ๐Ÿ‡ฌโ€Œ๐Ÿ‡ณโ€Œ๐Ÿ‡ธโ€Œ๐Ÿ‡ฌโ€Œ๐Ÿ‡ถโ€Œ๐Ÿ‡ตโ€Œ๐Ÿ‡ชโ€Œ๐Ÿ‡ฆโ€Œ๐Ÿ‡ฝโ€Œ๐Ÿ‡ฎโ€Œ๐Ÿ‡ฐโ€Œ๐Ÿ‡จโ€Œ๐Ÿ‡ทโ€Œ0โ€Œ๐Ÿ‡ถโ€Œ4โ€Œ๐Ÿ‡ฑโ€Œ1โ€Œ๐Ÿ‡ผโ€Œ2โ€Œ๐Ÿ‡ฉโ€Œ๐Ÿ‡ป", + converter.convert(&source, Font::Emoji) + ); + } } diff --git a/src/font.rs b/src/font.rs index 4dcca8f..dcb63c8 100644 --- a/src/font.rs +++ b/src/font.rs @@ -18,6 +18,7 @@ pub enum Font { BoldFraktur, Monospace, Blackboard, + Emoji, } impl Font { @@ -39,6 +40,9 @@ impl Font { Font::BoldFraktur => "๐–†๐–‡๐–ˆ๐–‰๐–Š๐–‹๐–Œ๐–๐–Ž๐–๐–๐–‘๐–’๐–“๐–”๐–•๐––๐–—๐–˜๐–™๐–š๐–›๐–œ๐–๐–ž๐–Ÿ๐•ฌ๐•ญ๐•ฎ๐•ฏ๐•ฐ๐•ฑ๐•ฒ๐•ณ๐•ด๐•ต๐•ถ๐•ท๐•ธ๐•น๐•บ๐•ป๐•ผ๐•ฝ๐•พ๐•ฟ๐–€๐–๐–‚๐–ƒ๐–„๐–…0123456789", Font::Monospace => "๐šŠ๐š‹๐šŒ๐š๐šŽ๐š๐š๐š‘๐š’๐š“๐š”๐š•๐š–๐š—๐š˜๐š™๐šš๐š›๐šœ๐š๐šž๐šŸ๐š ๐šก๐šข๐šฃ๐™ฐ๐™ฑ๐™ฒ๐™ณ๐™ด๐™ต๐™ถ๐™ท๐™ธ๐™น๐™บ๐™ป๐™ผ๐™ฝ๐™พ๐™ฟ๐š€๐š๐š‚๐šƒ๐š„๐š…๐š†๐š‡๐šˆ๐š‰๐Ÿถ๐Ÿท๐Ÿธ๐Ÿน๐Ÿบ๐Ÿป๐Ÿผ๐Ÿฝ๐Ÿพ๐Ÿฟ", Font::Blackboard => "๐•’๐•“๐•”๐••๐•–๐•—๐•˜๐•™๐•š๐•›๐•œ๐•๐•ž๐•Ÿ๐• ๐•ก๐•ข๐•ฃ๐•ค๐•ฅ๐•ฆ๐•ง๐•จ๐•ฉ๐•ช๐•ซ๐”ธ๐”นโ„‚๐”ป๐”ผ๐”ฝ๐”พโ„๐•€๐•๐•‚๐•ƒ๐•„โ„•๐•†โ„™โ„šโ„๐•Š๐•‹๐•Œ๐•๐•Ž๐•๐•โ„ค๐Ÿ˜๐Ÿ™๐Ÿš๐Ÿ›๐Ÿœ๐Ÿ๐Ÿž๐ŸŸ๐Ÿ ๐Ÿก", + // Following characters are regional indicator symbols, which is rendered as roman characters surrounded by square in some Websites. + // In some editor such as VSCode, A pair 'Z' and 'A' is rendered as South Africa flag. + Font::Emoji => "๐Ÿ‡ฆ๐Ÿ‡ง๐Ÿ‡จ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ซ๐Ÿ‡ฌ๐Ÿ‡ญ๐Ÿ‡ฎ๐Ÿ‡ฏ๐Ÿ‡ฐ๐Ÿ‡ฑ๐Ÿ‡ฒ๐Ÿ‡ณ๐Ÿ‡ด๐Ÿ‡ต๐Ÿ‡ถ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡บ๐Ÿ‡ป๐Ÿ‡ผ๐Ÿ‡ฝ๐Ÿ‡พ๐Ÿ‡ฆ๐Ÿ‡ง๐Ÿ‡จ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ซ๐Ÿ‡ฌ๐Ÿ‡ญ๐Ÿ‡ฎ๐Ÿ‡ฏ๐Ÿ‡ฐ๐Ÿ‡ฑ๐Ÿ‡ฒ๐Ÿ‡ณ๐Ÿ‡ด๐Ÿ‡ต๐Ÿ‡ถ๐Ÿ‡ท๐Ÿ‡ธ๐Ÿ‡น๐Ÿ‡บ๐Ÿ‡ป๐Ÿ‡ผ๐Ÿ‡ฝ๐Ÿ‡พ๐Ÿ‡ฟ๐Ÿ‡ฟ0123456789", }; source.chars().zip(target.chars()).collect()