Skip to content

Commit

Permalink
Merge pull request #43 from ikanago/emoji
Browse files Browse the repository at this point in the history
Emoji
  • Loading branch information
ikanago authored Sep 23, 2023
2 parents 0231697 + caa7c85 commit e8c2f3c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ on:
jobs:
release:
runs-on: ${{ matrix.job.os }}
outputs:
PROJECT_VERSION: ${{ env.PROJECT_VERSION }}
env:
PROJECT_NAME: "omekasy"
strategy:
Expand All @@ -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
Expand All @@ -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}"
Expand All @@ -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 }}

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
41 changes: 31 additions & 10 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
.join('\u{200C}'.to_string().as_str())
} else {
converted.collect()
}
}
}

Expand Down Expand Up @@ -213,4 +222,16 @@ mod tests {
converter.convert(&source, Font::Blackboard)
);
}

#[test]
fn emoji() {
let converter = setup_converter();
let source = "8WymXbLV3nINUhOoQkKGfuY9HsZSC675jzBEtATDFMRgPpeaxiJcr0q4l1w2dv"
.chars()
.collect::<Vec<_>>();
assert_eq!(
"8‌🇽‌🇾‌🇲‌🇾‌🇧‌🇲‌🇼‌3‌🇳‌🇯‌🇴‌🇻‌🇭‌🇵‌🇴‌🇷‌🇰‌🇱‌🇭‌🇫‌🇺‌🇿‌9‌🇮‌🇸‌🇿‌🇹‌🇩‌6‌7‌5‌🇯‌🇦‌🇨‌🇫‌🇹‌🇧‌🇺‌🇪‌🇬‌🇳‌🇸‌🇬‌🇶‌🇵‌🇪‌🇦‌🇽‌🇮‌🇰‌🇨‌🇷‌0‌🇶‌4‌🇱‌1‌🇼‌2‌🇩‌🇻",
converter.convert(&source, Font::Emoji)
);
}
}
4 changes: 4 additions & 0 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Font {
BoldFraktur,
Monospace,
Blackboard,
Emoji,
}

impl Font {
Expand All @@ -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()
Expand Down

0 comments on commit e8c2f3c

Please sign in to comment.